in reply to Greedy Substitution Within a Defined Range

Do it in two steps.

my $text =~ s[(?<=BEGIN_MARKER)(.*?)(?=END_MARKER)]{ (my $rep = $1) =~ s[i][x]g; # For single char subs you could use t +r// here $rep; }ge; print $text; An abitrary BEGIN_MARKER strxng whxch END_MARKER could contain BEGIN_M +ARKER just about END_MARKER anything

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail

Replies are listed 'Best First'.
Re: Re: Greedy Substitution Within a Defined Range
by diotalevi (Canon) on Apr 21, 2004 at 13:35 UTC
    Double points off for my ($rep = $1) =~ s/.... That should be two lines. This is how I'd solve the problem, btw. Nested substitutions are a really, really nice thing.

      Many many thanks to those who have given their time to help us. You make it look so easy, but I don't think it is really. We have used diotalevi's nested substitution solution -- it fits our purposes (and is remarkably fast).

      ::: Gratitude :::