in reply to how to find this substring?

Something like this should work:

if ($seq =~ /(ATG.*(TAA|TAG|TGA))/) { $subseq = $1; }

...roboticus

When your only tool is a hammer, all problems look like your thumb.