in reply to How do you make a regex non greedy

It's important to anchor both ends of a non-greedy match because the minimum that can be matched is nothing at all.

use strict; use warnings; my $str = "Some rubbish before TEST and the good stuff afterwards"; $str =~ s/^.*?(?=TEST)//; print $str;

Prints:

TEST and the good stuff afterwards

Not too the use of (?=TEST) which is a zero width look ahead match. It matches TEST, but doesn't consume it so you don't need to replace it later.

True laziness is hard work