in reply to testing for a zip file
You need the mime magic library (have a look at /etc/mime-magic on linux). The File (1) command uses this, and a quick search on CPAN reveals a File::MMagic module which purports to do something similar.