http://www.perlmonks.org?node_id=396570


in reply to Distinguishing text from binary data

Is there a CPAN module for this kind of thing?

There are numerous. Some of them even work on scalars, not only filehandles. Have a look at File::MimeInfo::Magic and File::LibMagic for a start.

For most similar tasks, yet not for your actual one you may find File::MMagic most useful.

Cheers, Sören