in reply to optimise perl code

I find your request odd. What is it that you want to optimise here? Sure you probably shave a few nanoseconds off the run time of this code by replacing it whith a s/// but really this code doesnt do enough for it to be an optimisation candidtate.

s/([^\\\/]+)$/$temp1.$temp2.$1/;

The only reason I can think of to change your code is to make it easier to read.

---
$world=~s/war/peace/g