my %count; my $max; for (split //, $string) {  $max = $count{$_} if ++$count{$_} > $max; }