$_ = "fox comes and fox goes into forest"; s!(\b(\w+)\b.*?)\2!$1the $2!; print $_;