my $buf; while (1) { my $nr = sysread(IN, $buf, 1024, length($buf)); unless ($nr) { ...handle EOF or error... }; ... if (length($buf)) { my $nw = syswrite(OUT, $buf, length($buf)); unless (defined($nw)) { ...handle error... } substr($buf, 0, $nw, ''); } ... }