use strict; use warnings; use threads; use Thread::Queue; my $queue = Thread::Queue->new(); my @threads = map {threads->new(\&worker)} 1..2; my @array = qw(2.1.1.1:1.3.1.8.1 ... 2.1.1.1:1.3.1.8.199); $queue->enqueue(@array); # Give work to threads after threads created $queue->end(); # Must do this, otherwise threads will never end $_->join for @threads; # Join threads to avoid thread errors at end of script sub worker { my $tid = threads->tid(); print "Starting thread $tid\n"; while (my $oid = $queue->dequeue()) { print "Thread $tid: Doing SNMP GET for $oid\n"; } print "Finishing thread $tid\n"; }