## sender my $size = -s 'theFileToSend'; print $socket pack 'N', $size; ## Assumes files less than 4GB. local $/ = \2**16; ## read the file in 64k chunks print $socket $_ while <$file>; ## The reader my $size; read( $sock, $size, 4 ); ## Get the size in binary $size = unpack 'N', $size; while( $size > 0 ) { my $buffer; my $chunkSize = $size < 2**16 ? $size : 2**16; $size -= read( $sock, $buffer, $chunkSize ); ## do something with this chunk }