my %count; $count{$_}++ foreach split //, $string; print "$count{$_}\n" foreach (@letters);