while ( $n_bytes_read = sysread( FILE, $inpbuf, 32 ) > 0 ) { if ( $n < 32 ) { # must be the last chunk # ... maybe this needs special treatment } process_input_bytes( $inpbuf ); }