sub method { my ($self, $deviceInfo, $count) = @_; my $machine = Connector->new($deviceInfo); while ($count) { my ($status, $hostname) = $self->cmd("hostname"); print "$count: $hostname\n"; sleep 1; --$count; } } my $thr1 = threads->create( 'method', $deviceInfo1, 10 ); my $thr2 = threads->create( 'method', $deviceInfo2, 6 );