Hi perl-diddler,
I am not sure if there is a reliable way to check for the encoding of a data stream. I found an article on the subject along with some modules on CPAN. See below. Maybe one of the modules will work for you.
What encoding am I (probably) using?
http://www.perlmonks.org/?node_id=456690
FILE::BOM
http://search.cpan.org/~mattlaw/File-BOM-0.14/lib/File/BOM.pm
Encode::Detect
http://search.cpan.org/~jgmyers/Encode-Detect-0.01/Detect.pm
Encode::Guess
http://search.cpan.org/~dankogai/Encode-2.56/lib/Encode/Guess.pm
I hope this helps.