#! perl use strict; use warnings; my $seq = 'AATGGTTTCTCCCATCTCTCCATCGGCATAAAAATACAGAATGATCTAACGAA'; # Adapted from the regex by stevieb my $re = qr{ ( # capture each sequence: ATG # - which begins with the codon ATG (?: [ACGT]{3} )*? # - followed by the smallest number of codons (?: TAG | TAA | TGA ) # - and ending with the codon TAG, TAA, or TGA ) }x; print "$1\n" while $seq =~ /$re/g;