my $string = "CCATGNNNTAACCNNATGNNTAGCC"; while ( $string =~ /([AG]TG.*?T[AG][AG])/ig ) { print "matched at $-[0]: $1\n"; }