use Modern::Perl; my $str = 'G_I1E2_GTGGAG^303CTGgacgCCCTGC_I2E3_TACA'; say for map s/[^ACGT]//gr, split 'gacg', $str;