in reply to Substitute _last_ occurence in string?
Probably valid only perl 5.6.0 +. Update: Above works only if two is followed by a space. It fails if:s/(two )(?!.*two )//
The following works. Also, the parentheses around the first two are unnecessary.$string = "one two three two four two";
$string =~ s/two\s*(?!.*two)//
|
|---|