for my $i (0 .. $#data) { if ( $data[$i] eq $data[$i+1] && $data[$i] =~ m/81|82/) { print "match $data[$i] starting at index $i\n"; } }