for (sort keys %histogram) { ... }; #### 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}++ }; #### my %validchars; if ( $arg eq '-a' ) { %validchars = map { $_ => uc $_ } ( \x00 .. \xff ); } elsif ( $arg eq '-c' ) { %validchars = map { $_ => $_ } ( 'A' .. 'Z', 'a'..'z' ); };