my $server = IO::Socket::INET->new(...); while (my $client = $server->accept) { if (my $pid = fork()) { # parent waits for another connection close $client } elsif (defined $pid) { # child handles the request while (<$client>) { ... } ... close $client; close $server; exit; } } close $server;