in reply to Re^2: Matching and replacing the minimum string from the tail of the regex
in thread Matching and replacing the minimum string from the tail of the regex

For some reason, I had trouble with your code. Instead I turned the problem on it's head.
use strict; my $lines = do{ local $/; <DATA> }; # reverse the order of the lines so that the RE matches the # last part of the region first my $reversetext = join("\n", reverse(split("\n",$lines))); $reversetext =~ s/^[^\n]*e p.*?s[^\n]*\n//msg; # put the lines in normal order again $lines = join("\n",reverse(split("\n", $reversetext))); print $lines; __DATA__ Random String s erartt e p s foo e f blah blah s adflkja wibble wobble e p End of file

==
Kwyjibo. A big, dumb, balding North American ape. With no chin.
  • Comment on Re^3: Matching and replacing the minimum string from the tail of the regex
  • Download Code