in reply to Greedy Substitution Within a Defined Range

Use Regexp::Common just for the case, that begin and end markers are nested.
#!/usr/bin/perl use Regexp::Common 'balanced'; my $text = 'An abitrary BEGIN_MARKER string which END_MARKER could con +tain BEGIN_MARKER just about END_MARKER anything' ; my $q; $q = qr!$RE{balanced}{-begin => "BEGIN_MARKER"}{-end => "END_MARKER"}{ +-keep}!; $text =~ s:$q:local $_ = $1; s/a/X/; $_:eg; print $text;
Boris