use Modern::Perl; use Data::Dump qw /dump/; my @results; while () { my @codon = split '', (split /\s+/)[1]; while (my ($seq, $char) = each @codon) { $results[$seq]{$char}++; } } say dump(@results); __DATA__ first ACGATT--GAT second AGTTAAC-TTT third TTAGCAGG-TA