use strict; use warnings; my $infile = 'hi.txt'; my $outfile = 'hi.gz'; open my $in, '<:raw', $infile or die $!; open my $out, '>:gzip', $outfile or die $!; while(defined( my $read = read $in, my $s, 2048 ) ){ die "Error reading 2048: $!" if $read != 2048; print {$out} $s; } close $in; close $out;