use strict; use warnings; my @number = (1,2,3,9432, 5,6,7); my $count=0; for (0 .. (($#number < 99) ? $#number : 99)) { if ($number[$count]=~/^9432$/g) { print "match found\n"; } else { print "match failed\n"; } $count++; } #### use strict; use warnings; my @number1 = (2 .. 9432); my @number2 = (2 .. 9433); #I intentionally avoided the use of (1.. 9432) here, to remove the doubt whether it compares against the last element of the array. my @number3 = (2 .. 9434); my $count=0; if (@number1 =~ /^9432$/g) { print "match found\n"; } else { print "match failed\n"; } if (@number2 =~ /^9432$/g) { print "match found\n"; } else { print "match failed\n"; } if (@number3 =~ /^9432$/g) { print "match found\n"; } else { print "match failed\n"; }