$sentence =~ s/\b\Q$word\E\b\s+(?!.*\b\Q$word\E\b)//s; #### String: the quick brown dog jumped the doggy style dog killing doggie eater. Result: the quick brown dog jumped the doggy style killing doggie eater. #### $sentence =~ s/\s*\b\Q$word\E\b(?!.*\b\Q$word\E\b)//s;