The arrays contain data similar to this: @truncated_sequences = qw(JFADLKGJLFLGJGAFDJ DSJLJFLDJSLF...E.T.C); @triamino_combo = qw(AAA AAB AAC AAD.......e.t.c); foreach $prot_string (@truncated_sequences) { foreach $tri_seq (@triamino_combo) { while ($prot_string =~ /$tri_seq/g) { $tri_freq{$tri_seq}++; } } } #### foreach $prot_string (@truncated_sequences) { foreach $tri_seq (@triamino_combo) { if ($prot_string =~ /$tri_seq/g) { $tri_freq{$tri_seq}++; } else { $tri_freq{$tri_seq} = "0"; } } }