while ( $line = <$sock> ) { push @output, $line; } print $sock "BYE\n"; #### # In the server script sub process { ... print $new_sock <) !~ /^123/ ) { push @output, $line; } print $sock "BYE\n"; }