use IO::Select; use IO::Socket; $lsn = new IO::Socket::INET(Listen => 1, LocalPort => 8080); $sel = new IO::Select( $lsn ); while(@ready = $sel->can_read) { foreach $fh (@ready) { if($fh == $lsn) { # Create a new socket to handle more conns $new = $lsn->accept; $sel->add($new); # register it with IO::Select } else { # Process socket my $data = <$fh>; if ( $data =~ m/exit/i ) { print $fh "Sayonara!\n"; $sel->remove($fh); $fh->close; } else { print $fh "Hello $data\n"; } } } }