use sshConnector; sub methodA { my $self = shift; my $count = shift; my $hostname; while ($count) { ($status,$hostname) = $self->cmd("hostname"); print "$count : $hostname\n"; sleep 1; $count--; } } sub methodB { my $self = shift; my $count = shift; my $hostname; while ($count) { ($status,$hostname) = $self->cmd("hostname"); print "$count : $hostname\n"; sleep 2; $count--; } } my $machine1 = new Connector($deviceInfo1); my $thr1 = threads->create('methodA',$machine1,10); my $machine2 = new Connector($deviceInfo2); my $thr2 = threads->create('methodB',$machine2,6); $thr1->join(); print "First thread over\n"; $thr2->join(); print "Second thread over\n";