# Build a list of keys sorted (descending because $b is on the left) by the number of occurrences my @sorted_by_count = sort { $count{$b} <=> $count{$a} } keys %count; # Print the top 10: print "$_ occurred $count{$_} times\n" for @sorted_by_count[0 .. 9];