use Socket; my $ip = '127.0.0.1'; print unpack('N', inet_aton($ip)),"\n"; __END__ 2130706433 #### my $ip = '127.0.0.1'; print unpack('N', pack 'C*', split /\./, $ip),"\n"; __END__ 2130706433 #### use Socket; chomp(my @ips = ); my @sorted = map { $_->[1] } # pull out second element sort {$a->[0] <=> $b->[0]} # sort list of arrays by first element map { [ # construct an anonymous array with a unpack('N',inet_aton($_)), # transformed IP address $_ # and IP address ] } @ips; # your input list print "$_\n" for @sorted; __DATA__ 192.168.10.15 10.24.13.88 172.16.254.13 10.24.13.89 89.67.128.254 #### 10.24.13.88 10.24.13.89 89.67.128.254 172.16.254.13 192.168.10.15