use IO::Seekable; open(OUTPUT, ">> $outfile") or die "can't open file $outfile: $!"; seek OUTPUT, 0, 0; # seek to the beginning of the file? print OUTPUT "\037\213"; # append gzip magic (0x1F 0x8B) close OUTPUT;