in reply to regexp find last word
$_ = "fox comes and fox goes into forest"; s!(\b(\w+)\b.*?)\2!$1the $2!; print $_; [download]
"fox goes into forest" [download]