in reply to array and counting

Append the first 3 characters from the next sequence to the end of the current sequence. Keep a variable holding how many items you started with, and use that to control the loop, instead of using $i<@gene directly:
my @gene = split //, $seq[$i]; my $count = @gene; if($i < $#seq) { push @gene, split //, substr $seq[$i+1], 0, 3; } # Now, proceed as before: for (my $i=0; $i<$count; $i+=3) { ... }

p.s. You don't actually need to split the strings into arrays, a plain proper use of substr will work just as fine, as in:

substr($genestring, $i, 1)