while ($text =~ m/(TATAAT|TTGACAT)\w+[^ATG]?(ATG\w+)[^TAG|TAA|TGA]?/g) { my $match = $2; $match =~ tr/ATGC/UACG/; print $match; }