binmode($fh_in); # Or open with :raw binmode($fh_out); # Or open with :raw while (1) { # Or this could be a select loop. my $rv = sysread($fh, my $buf, BLOCK_SIZE, length($buf); die($!) if !defined($rv); last if !$rv; print($fh_out $buf); }