#!/bin/perl -w use warnings; use strict; use Archive::Zip qw( :ERROR_CODES :CONSTANTS); #almost verbatim from the Archive::Zip docs: my $zip = Archive::Zip->new(); my $member = $zip->addFile('t.out'); die 'Error writing file' if $zip->writeToFileNamed('foo.zip') != AZ_OK; #### #!/bin/perl -w use warnings; use strict; require 5.004; #using TIEHANDLE interface use IO::Zlib; tie *FILE, 'IO::Zlib', "foo.txt.gz", "wb"; #do your stuff here #everything written to FOO gets compressed and stored in foo.gz print FILE "hello world\n";