#!c:/perl/bin/perl -w $|++; use strict; use CGI::Simple; use Archive::Zip; my $fileToUpload = 'foobar.txt'; my $CGI = CGI::Simple->new(); my $zip = Archive::Zip->new(); open( my $fh, '<', $fileToUpload ) or die "open failed: $!"; binmode( $fh ); # for win32 my $contents = do { local $/; <$fh> }; close( $fh ); $zip->addString($contents, $fileToUpload); print $CGI->header( -type => 'application/zip', -attachment => "$fileToUpload.zip" ); binmode( STDOUT ); # once again, for win32 $zip->writeToFileHandle(\*STDOUT);