s/(two )(?!.*two )// #### $string = "one two three two four two"; #### $string =~ s/two\s*(?!.*two)//