use strict; use diagnostics; use threads; my @array_of_threads; my $i =0; my $string; sub first{ print "called first"; &second();} sub second { ## creating 5 threads for ($i ; $i<5;$i++) { $array_of_threads[$i]=threads->new(\&sub1,"$i"); print "End of thread ".int($i+1)." creation\n"; } &complete(); } sub complete{ print "The threads have completed the execution\n";} sub sub1{ my $j=$_[0]; print "Thread $j has entered sub1\n"; &sub2($j);} sub sub2{ my $k= shift; ## loop for thread 3 to show that time for processing the threads maybe different if($k==3) { for (my $in=0;$in<500;$in++){ print "Thread $k has entered sub2 --- $in\n"; }} } &first();