my $header_line = ; my %count; my @chars = ( qw/F G S/ ); while (my $line = ) { eval "\$count{$_} += \$line =~ tr/$_/$_/,1" or die $@ foreach @chars; } print "There are $count{$_} occurrences of $_\n" foreach sort keys %count; __DATA__ Sample header hine FDIELSIGCOXLSAGICK\n FDIELSIGCOXLSAGICK\n #### use strict; use warnings; my $header_line = ; my %count; my @chars = ( qw/F G S/ ); while ( my $line = ) { foreach ( @chars ) { my $pos = 0; while ( ($pos = index( $line, $_, $pos ) ) >= 0) { $count{$_}++; $pos++; } } } print "There are $count{$_} occurrences of $_\n" foreach sort keys %count; __DATA__ Sample header hine FDIELSIGCOXLSAGICK\n FDIELSIGCOXLSAGICK\n