sub client_connect { my($connection) = @_; my $kidpid; die "can't fork: $!" unless defined($kidpid = fork()); if ($kidpid) { # parent copies the socket to standard output while (<$connection>) { last if /Close_Server/; } kill("TERM" => $kidpid); # send SIGTERM to child } else { while (1) { print $connection "some output\n"; } continue { sleep 10; } } }