in reply to Using Recursion to Find DNA Sequences

Here is an approach that will get the results. It uses more of an iterative method.
#!/usr/bin/perl use strict; use warnings; my $seq = "AATGGTTTCTCCCATCTCTCCATCGGCATAAAAATACAGAATGATCTAA"; my @beg; push @beg, $-[0] while $seq =~ /ATG/g; my @end; push @end, $+[0] while $seq =~ /T(?:AG|AA|GA)/g; my @data; for my $i (@beg) { for my $j (@end) { next if $j-$i < 6; push @data, substr $seq, $i, $j-$i; } } print "$_\n" for @data;
Output:
ATGGTTTCTCCCATCTCTCCATCGGCATAA ATGGTTTCTCCCATCTCTCCATCGGCATAAAAATACAGAATGA ATGGTTTCTCCCATCTCTCCATCGGCATAAAAATACAGAATGATCTAA ATGATCTAA