{ binmode(INPUT); binmode(OUTPUT); local $_= ""; while( read( INPUT, $_, 4096, length($_) ) ) { if( s/^.*?(\x0d\x0a)/$1/s ) { print OUTPUT $_; last; } substr( $_, 0, -1 )= ""; } print OUTPUT $_ while read INPUT, $_, 4096; }