foreach (@file) { open input file or die... my $part=1; my $sizeRead; while ($sizeRead = read $in_fh, $buffer, $chunk;) { open out file for the current part number increment part number for next time if there is such write the data...using $sizeRead (what was actually read) } if $sizeRead is undef, last read didn't "work". }