use strict; my %hash; while () { chomp; my @chars = split ''; for my $char (@chars) { # use the next line if case doesn't matter # $hash{lc $char}++; $hash{$char}++; } print join " ", @chars, "\n"; } my $consensus = ''; for (sort keys %hash) { $consensus = $_ if $hash{$_} > $hash{$consensus}; print "\$hash{$_}: $hash{$_}\n"; } print "\nChar: '$consensus' has the highest count: $hash{$consensus}!\n"; __DATA__ aAabbbbcdDeeeeEEefFFffffffffffff zzzzzzzxxxxxxxxxyyYyg #### a A a b b b b c d D e e e e E E e f F F f f f f f f f f f f f f z z z z z z z x x x x x x x x x y y Y y g $hash{A}: 1 $hash{D}: 1 $hash{E}: 2 $hash{F}: 2 $hash{Y}: 1 $hash{a}: 2 $hash{b}: 4 $hash{c}: 1 $hash{d}: 1 $hash{e}: 5 $hash{f}: 13 $hash{g}: 1 $hash{x}: 9 $hash{y}: 3 $hash{z}: 7 Char: 'f' has the highest count: 13!