for my $key (sort { length($hash{$a}) <=> length($hash{$b}) } keys %hash) { print "$key : $hash{$key}\n"; }