in reply to Count every 3rd base occurence

Try incrementing by three rather than by one and then looking ahead three. At present, you're iterating over each element in the array and then checking to see the value of your index plus 3. So you're seeing 4, then 5, 6, 7, since you start counting at 1. Try a loop construct like:

for ($i = 2; $i < @dna; $i += 3) # assuming your start index is 0