#! perl -slw use strict; use threads; use IO::Socket; our $W //= 20; my @t = map{ async { for( 1 .. rand 1000 ) { my $s = new IO::Socket::INET( 'localhost:12345' ) or die "Failed to connect to server: $!"; for( 1 .. rand 1000 ) { print $s "Message $_"; scalar <$s>; } close $s; } }; } 1 .. $W; $_->join for @t;