use threads; my %device_ip = ( core => "3.3.3.3", border => "5.5.5.5", ); # Initialize devices' pool of threads. my $index = 0; my @th; while (my ($k, $v) = each %device_ip) { push @th, threads->new(\&thread_job, $k, $device_ip{$k}, $index++) } $_->join for @th; # Worker thread subroutine. sub thread_job { my ($dev, $ip, $i) = @_; my $tid = threads->tid(); print qq![id=$tid @ $i]: IP address "$ip" corresponds to device "$dev".\n!; }