use strict; my %hash = ( Key1 => [qw(a b b b a a c d b d b)], Key2 => [qw(c a b a b d c c d d d e f)], ); for (sort keys %hash) { my %counted; $counted{$_}++ for @{$hash{$_}}; print "$_:\n"; for (sort { $counted{$b} <=> $counted{$a} } keys %counted) { print "\t$_ = $counted{$_}\n"; } }