#!/usr/bin/perl
$seq ="CGGTTAATGGGAATACGCGGATAAGGCGAAATGCACCACGACGCCATAATTTGAAGGATG";
#            ^^^............^^^      ^^^..................^^^   ^^^

while ( $seq =~ /ATG(([ATGC]{3})([ATGC]{3})*?\2)(TAG|TAA|TGA)/g ) {
    print "$1\n";
}

