#! perl -slw use strict; use threads; use IO::Socket; my $t1 = async { my $s = IO::Socket::INET->new( 'localhost:12345' ); for ( 1 .. 1e6 ) { printf $s "Message %6d\n", $_; printf 'Sent and received: %s', scalar <$s>; sleep 1; } }; my $t2 = async { my $s = IO::Socket::INET->new( 'localhost:54321' ); for ( 1 .. 1e6 ) { printf $s "Message %6d\n", $_; printf 'Sent and received: %s', scalar <$s>; sleep 1; } }; $_->join for $t1, $t2;