use Archive::Tar; $tar = Archive::Tar->new(); $tar->read("origin.tar.gz",1); # you don't seem to want this line though $tar->add_files("file/foo.c", "file/bar.c"); $tar->add_data("file/baz.c","This is the file contents"); # $tar->write("files.tar"); print STDOUT $tar->write(); # make sure http headers are already printed before running this line