http://qs321.pair.com?node_id=631977


in reply to Matching and replacing the minimum string from the tail of the regex

I'm not sure if there is a better way, but to me the obvious approach is to accept 'start' followed by '(not start)*' followed by 'end':

my $lines = do { local $/; <DATA> }; $lines =~ s{ ^ s \n # start line (?: ^ (?! s \n ) .* \n )* # body excluding new start line ^ e\ p $ # end line }{}xmg; print $lines;

Note that this does more work than the original failing substitution, so you can expect it to be slower.

I'm assuming that the start of a test is "an 's' followed by a newline", and on that assumption being a bit stricter than your original example about matching that.

Hope this helps,

Hugo