#!/usr/bin/perl use strict; use warnings; use Net::IP qw/ip_iptobin/; my %temphash = ( '1AHIT' => { COMMENT => '1AHIT', IP => '192.168.221.10' }, '2AHIT' => { COMMENT => '2AHIT', IP => '192.168.222.10' }, 'CAD1-OST' => { COMMENT => 'CAD1-OST', IP => '192.168.43.10' } ); my @keys_sorted_by_ip = sort { ip_iptobin($temphash{$a}{IP}, 4) cmp ip_iptobin($temphash{$b}{IP}, 4) } keys %temphash; print map { "$_: IP = $temphash{$_}{IP}\n" } @keys_sorted_by_ip;