use Fcntl qw(:DEFAULT :flock); sysopen(OUTPUT, "output.bin", O_CREAT|O_EXCL|O_WRONLY) or die $!; binmode OUTPUT; while (read(my $fh, my $buffer, 4096)) { print OUTPUT $buffer; } close OUTPUT or die $!;