in reply to How do I delete the last instance of a word from a string?

Although I prefer the rindex/substr solution, another alternative involves regular expressions with "zero-width negative look-ahead assertions": s/\Q$word\E(?!.*\Q$word\E)//s or, if you really only want "words": s/\b\Q$word\E\b(?!.*\b\Q$word\E\b)//s