#!/usr/bin/perl use strict; use warnings; use Coro qw( async ); use IO::Socket::INET qw( ); sub client { my ($sock) = @_; my $host = $client->peerhost; print "[Accepted connection from $host]\n"; while (!eof($sock)) { my $msg = <$sock>; if (!defined($msg)) { print "[Error reading from host $host]\n"; return; } print "$host said '$msg'\n"; last if $msg eq 'quit'; } print "[Connection from $host terminated]\n"; } my $server = IO::Socket::INET->new( ... ) or die("Couldn't create server socket: $!\n"); async(\&client, $server->accept) while 1;