use Archive::Zip; my $zip = Archive::Zip->new(); # new instance chdir("/$NewHomePath/Results"); @files = (<$InvoiceNumber/*.ab1>); # files to store @filesA = (<$InvoiceNumber/*.seq>); # files to store push (@files,@filesA); #PRINT HEADER print "Content-Type:application/zip\n"; print "Content-Disposition:attachment;filename=$FileNameToWrite\n\n"; #NOW PRINT TO STDOUT foreach $file (@files) { if ($DLWOSC eq "checked"){ $TranslatedName=(split('/',$file))[-1]; $TranslatedName=~s/\;/\_/g; $zip->addFile($file,$TranslatedName); # add files $zip->writeToFileHandle(*STDOUT); }else{ $zip->addFile($file); $zip->writeToFileHandle(*STDOUT); } }