#!/usr/bin/perl -w use strict; print map { "$_->[0]\n" } # 4. pull out the name sort { $a->[1] cmp $b->[1] } # 3. sort by key map { [$_, /[^\d.]/ ? # 2. make key: is it an ip or hostname? join '' => reverse split /\./ : # host -- key is reversed parts pack "xC4" => split /\./ ] } # ip -- key is packed addr map { chomp; s/\s*#.*$//; $_ } <>; # 1. read in lines and strip comments