in reply to Why does this have strange results.

In this line:

$compressed =~ s/\\|/x02/g;

you should escape the pipe "|", too.

$compressed =~ s/\\\|/x02/g;

Rule One: "Do not act incautiously when confronting a little bald wrinkly smiling man."