#!/usr/bin/perl -w use strict; use IO::Socket; use threads; use threads::shared; my $server = IO::Socket::INET->new( Proto => 'tcp', LocalPort => $ARGV[0], Listen => SOMAXCONN, Reuse => 1); die "can't setup server" unless $server; share(my @jobs); while (my $client = $server->accept()) { $client->autoflush(1); print "[Connect from ". $client->peerhost . ":" . $client->peerport . "]\n" ; # clients address my $thr = threads->new(sub { push(@jobs,share($client)); ### NOTE THIS IS UNSHARABLE ### while (<$client>) { if (/test/i){ print $client "looks good, @jobs\n"; } elsif (/quit/i){ print $client "bye\n"; last; } } # finishe while } )->detach; close $client; }