in reply to Why does this have strange results.

s/\\:/x01/g; # Replaces each "\" followed by ":" s/\\|/x02/g; # Replaces each "\" and zero-length string s/\\~/x03/g; # Replaces each "\" followed by "~" s/\\\\/x04/g; # Replaces each "\" pair

And there's a zero-length string between each character.

I think you want:

s/\\:/x01/g; # Replaces each "\" followed by ":" s/\\\|/x02/g; # Replaces each "\" followed by "|" s/\\~/x03/g; # Replaces each "\" followed by "~" s/\\\\/x04/g; # Replaces each "\" pair
or
s/:/x01/g; # Replaces each ":" s/\|/x02/g; # Replaces each "|" s/~/x03/g; # Replaces each "~" s/\\/x04/g; # Replaces each "\"