What has your investigation of the data itself told you? When you load the data into your Perl script and output it from there, for example to a file, and you open that file both in an editor and you produce a hex dump of that file, does it look correct, like base64 encoded data? When you compare a dump of a file that works with a file that doesn't work, what differences do you see?