in reply to Replace all occurrences but the last

1 while s/ \. ( .* \. ) /_$1/x;

You can also make that non-greedy, it doesn't matter.

Makeshifts last the longest.