#create the array with the ip:OID use warnings; use strict; use Thread qw(async); use threads::shared; share (my @array); @array = qw/2.1.1.1:1.3.1.8.1 2.1.1.1:1.3.1.8.2 2.1.1.1:1.3.1.8.3 2.1.1.1:1.3.1.8.4 2.1.1.1:1.3.1.8.5 2.1.1.1:1.3.1.8.6 2.1.1.1:1.3.1.8.7....sequence continues upto....2.1.1.1:1.3.1.8.199 2.1.1.1:1.3.1.8.200/; my $thr1 = async { my $log = ""; while($#array > 0) { print "Thread 1: size of the array is $#array\n"; my @my_oids; { lock (@array); # Block until we get access to $a for(my $i=0;$i<10;$i++) { push (@my_oids, (pop @array)); } } foreach(@my_oids) { print "Thread 1: Doing SNMP GET for $_\n" if (defined($_)); $log .= "Thread 1: Doing SNMP GET for $_\n"; } } return $log; }; my $thr2 = async { my $log = ""; while($#array > 0) { print "Thread 2: Size of the array is $#array\n"; my @my_oids; { lock (@array); # Block until we get access to $a for(my $i=0;$i<10;$i++) { push (@my_oids, (pop @array)); } } foreach(@my_oids) { print "Thread 2: Doing SNMP GET for $_\n" if (defined($_)); $log .= "Thread 2: Doing SNMP GET for $_\n"; } } return $log; }; my $log1 = $thr1->join; my $log2 = $thr2->join; my $file = 'threadinfo.txt' open(my $output,">",$file) or die "Unable to open file '$file': $!"; print $output $log1; print $output $log2; close($output);