my $sock = new IO::Socket::INET ( LocalHost => $server, LocalPort => 9200, Proto => 'tcp', Listen => 2, ReuseAddr => 1, ); die "socket creation error: $!" unless $sock; while( my $client = $sock->accept() ) { binmode $client, ":utf8"; $client->autoflush(1); # Read data while( $client->recv( $in_buffer, $buffer_size ) ) { # Store data } # Process data # Return data $client->send( $output ); }