in reply to How do I read .pag files
File::Type is designed for precisely this purpose.
Thank you! I misunderstood the original question.
There also are other modules to determine the type of a file, File::MMagic, File::MimeInfo and MIME::Detect.