I've only used it on .zip files, not .gz files, but have a look at Compress::Zlib as it seems from the documentation that it could be what you need.
Cheers,
JohnGG
Update: I'm not sure what I was on when I wrote that nonsense about .zip files. I have, of course, used Compress::Zlib on .gz files, it was Archive::Zip that I used on .zip files.