Simulating Regexp replace