use IO::Socket; use IO::Select; my $s = new IO::Socket::INET ( LocalPort => '5800', Proto => 'tcp', Listen => 1, Reuse => 1, ); die "Could not create socket: $!\n" unless $s; $read_set = new IO::Select(); $read_set->add($s); while (1) { my $rh_set = IO::Select->select($read_set, undef, undef, 0); foreach $rh (@$rh_set) { if ($rh == $s) { $ns = $rh->accept(); $read_set->add($ns); } else { $buf = <$rh>; if($buf) { print $buf; } else { $read_set->remove($rh); close($rh); } } } }