I think Zaxo's code is not doing the same thing. He is reversing each pair, and you are moving the first letter through each position in turn, and using each intermediate step. There is a nice Perlish way to
in a loop and process each in turn, but it doesn't work with s///. You might be able to simplify your code a little, but trying to get a regex to do it would be more obscure than what you have now.