in reply to Replace text at given index

Maybe something like

substr($s,rindex($s,$searchstring),length($searchstring))=$replacestri +ng;
? However, this assumes that you *do* find the searchstring. If the searchstring is not found, rindex returns -1. You would have to catch this with eval.

Note that my solution would start looking for the searchstring always from the end. In particular, it would also consider the replacement you have done earlier. If you don't want to do this, things get even more complicated.
-- 
Ronald Fischer <ynnor@mm.st>