my %validchars = map { $_ => uc $_ } (qw( A B C D E F ... Z a b c d ... z )); # this sets # $validchars{A} = A # ... # $validchars{Z} = Z # $validchars{a} = A # ... # and the later: if (exists $validchars{$_}) { my $target = $validchars{$_}; $histogram{$target}++ };