Do the replacement on a copy of the text