This meets the spec, though probably not your requirements:

#! perl -slw use 5.010; use strict; use threads; sub sub1 { say"sub1 starts"; say("sub1:$_"),sleep 1 for 1..3; say"sub1 + ends" } sub sub2 { say"sub2 starts"; say("sub2:$_"),sleep 1 for 1..3; say"sub2 + ends" } sub sub3 { say"sub3 starts"; say("sub3:$_"),sleep 1 for 1..3; say"sub3 + ends" } sub sub4 { say"sub4 starts"; say("sub4:$_"),sleep 1 for 1..3; say"sub4 + ends" } sub sub5 { say"sub5 starts"; say("sub5:$_"),sleep 1 for 1..3; say"sub5 + ends" } sub sub6 { say"sub6 starts"; say("sub6:$_"),sleep 1 for 1..3; say"sub6 + ends" } sub sub7 { say"sub7 starts"; say("sub7:$_"),sleep 1 for 1..3; say"sub7 + ends" } sub sub8 { say"sub8 starts"; say("sub8:$_"),sleep 1 for 1..3; say"sub8 + ends" } my $t1 = async{ sub1(); async { sub3(); }->detach; sub4(); }; my $t2 = async{ sub2(); async{ sub5(); }->detach; sub6(); }; $_->join for $t1, $t2; my $t3 = async{ sub7() }; sub8(); $t3->join; print "main ends"; __END__ c:\test>854022.pl sub1 starts sub1:1 sub2 starts sub2:1 sub1:2 sub2:2 sub1:3 sub2:3 sub1 ends sub4 starts sub3 starts sub4:1 sub3:1 sub2 ends sub6 starts sub6:1 sub5 starts sub5:1 sub4:2 sub3:2 sub6:2 sub5:2 sub3:3 sub4:3 sub6:3 sub5:3 sub4 ends sub3 ends sub6 ends sub5 ends sub8 starts sub8:1 sub7 starts sub7:1 sub8:2 sub7:2 sub8:3 sub7:3 sub8 ends sub7 ends main ends

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP an inspiration; A true Folk's Guy

In reply to Re: multithreads newbie question by BrowserUk
in thread multithreads newbie question by daverave

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.