my @data = ; my $value = 0; for (0..$#data) { if ($data[$_] =~ /ABC SET/ and $data[$_+2] =~ /^--/) { $value++; } }