server: use strict; use IO::Socket; use threads; $|++; my $server = IO::Socket::INET->new(LocalPort => '5123',Reuse => 1,Listen => 5) or die "Could not create server: $!\n"; while (my $client = $server->accept()) { threads->create(\&talk_with_one_client, $client)->detach(); } sub talk_with_one_client { my $client = shift; while (my $line = <$client>) { print $line; chomp $line; print $client $line + 1, "\n"; } } client: use strict; use IO::Socket; $|++; my $socket = IO::Socket::INET->new(PeerAddr => "localhost", PeerPort => '5123', Proto => "tcp") or die "Could not create client: $!\n"; print $socket "1\n"; while (my $line = <$socket>) { print $line; chomp $line; sleep 1; print $socket $line + 1, "\n"; }