my %hist; while(<$fh>){ ++$hist{ $_ } for split //; } for(sort{ $hist{ $b } <=> $hist{ $a } } keys %hist){ print "'$_' => $hist{ $_ }\n"; }