sub mysort { $a <=> $b; } foreach $i ( sort mysort ( keys %myhash ) ) { print "$i\n"; }