#! perl -slw use strict; use threads; my @threads = map async( sub{ my $num = shift; print "started thread $num"; sleep $num; print "done with thread $num"; return $num; }, $_ ), 1 .. 3; print "Done with ", $_->join for @threads; __END__ C:\test>junk52 started thread 1 started thread 2 started thread 3 done with thread 1 Done with 1 done with thread 2 Done with 2 done with thread 3 Done with 3 #### #! perl -slw use strict; use threads; my @threads = map async( sub{ my( $num, $sleep ) = @_; print "started thread $num to sleep for $sleep seconds"; sleep $sleep; print "done with thread $num"; return $num; }, $_, 2+int( rand 3 ) ), 1 .. 3; print "Done with ", $_->join for @threads; __END__ C:\test>junk52 started thread 1 to sleep for 4 seconds started thread 2 to sleep for 3 seconds started thread 3 to sleep for 2 seconds done with thread 3 done with thread 2 done with thread 1 Done with 1 Done with 2 Done with 3 #### print "Done with ", $_->join for @threads;