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