while( data = read_data(fh) ) { if( data_to_modify(data) ) { out_fh->write(modified_data); last; # break out } } while( read(fh,buffer,buffer_size) ) { out_fh->write(buffer); }