File::Type is designed for precisely this purpose.
In reply to Re: How do I read .pag files by hippo in thread How do I read .pag files by sachinz2