# Takes a string, returns hash of chars in string and # how many times each appears. sub char_count { my $str = shift; my %count; while ($str =~ /(.)/gs) { ++$count{$1}; } return %count; }