#!/usr/bin/perl use strict; use warnings; use threads; sub func { print "doing job ... \n"; sleep 1; } my @threads; foreach ( 1..2 ) { print "launching job\n"; push( @threads , threads->new( \&func )); } foreach my $thread ( threads->list() ) { my @command_output = $thread->join ; print "job done\n"; } #### package myTest; sub new { my $item={}; bless $item; return $item; } sub myTestFunc { my $item = shift; print "doing job ... \n"; } 1; #### #!/usr/bin/perl use strict; use warnings; use threads; use myTest; my @threads; foreach ( 1..2 ) { print "launching job\n"; my $test = myTest->new(); push( @threads , threads->new( $test->myTestFunc )); } foreach my $thread ( @threads ) { my @command_output = $thread->join ; print "job done\n"; } #### Thread 1 terminated abnormally: Undefined subroutine &main::1