use strict; use warnings; my @letters = qw(A B C D E F); my $string = "AFTYUBEWTWECRTUTYIYTDDDDRYJURTHJTREEEEEFGSDFF"; my %chCount; ++$chCount{$_} for split '', $string; print "$_ = $chCount{$_}\n" for @letters;