or s/(fox(?:(?!fox).)*forest)/the $1/;
Update: nm, capture makes it slower.
In reply to Re^2: regexp find last word by ikegami in thread regexp find last word by Murcia