1 while $text =~ s/(BEGIN_MARKER(?:(?!END_MARKER).)*?)a(.*?END_MARKER)/$1x$2/;