Here is something I did once while sorting a hash keyed by IP address. Just to show another way of sorting things out. The results above are both very good replies and are detiled to your specific question, but for what it's worth...here is my code.
sub sort_ips()
{
my %counts;
my $hash_ref = shift;
print "Subnet\t\tCount\n";
foreach my $ip(keys(%$hash_ref)) {
my $subnet = pack 'C3', split /\./, $ip;
$counts{$subnet}++;
}
foreach my $subnet(sort keys(%counts)) {
print join '.', unpack 'C3', $subnet;
print ":\t$counts{$subnet}";
print "\n";
}
print "\n";
}
seanbo