in reply to
replacing special characters in file
The way I see it, you need to output some printable characters, so that you can (or should be able to) get the original "special" characters for verification.
In such cases, you should look at Mime::Base64 which would encode any character to a printable one based on a 65-character set.To get back the original string all you need to do is decode it. I was having a similar issue a few days ago, and ikegami suggested the same. Hope it works for you as well.