Say, a text file have many $start-$end
pairs, and within each pair there are some text. I want Perl to find-and-replace all $pattern
s with the
Eventually used following code to accomplish what I intended:
$_ = "xx START xx bingo xx bingo xx END xx bingo xx START xx bingo xx END bingo";
print;
print "\n";
$_ =~ s/START.*?END/($s=$&) =~ s,bingo,okyes,g; $s/ge;
print;
This is a one-regex solution, using embedded expression in s///g
regex, and nested s///g
regexes.
Sorry for this late post, but I deeply appreciate the replies by @Sobrique, @Borodin and @choroba, which are enlightening and helpful.