#! perl -slw use strict; use threads; use threads::shared; sub concatenate_parallel { my( $contentRef, $letter ) = @_; sleep 1 + rand 2; ## Do stuff that takes time { lock $contentRef; $$contentRef .= $letter for 1 .. 1e4; } } my $content : shared = ''; my $contentRef = \$content; print scalar localtime; my @threads = map{ threads->create( \&concatenate_parallel, $contentRef, $_ ); } 'a' .. 'z'; $_->join for @threads; print $content; print scalar localtime; __END__ c:\test>579015 Thu Oct 19 00:33:11 2006 cbefghlmqsvwadijknoprtuxyz Thu Oct 19 00:33:13 2006