my $flag = 0; for (@B) { if (/$A[0]/ || /$A[1]/) { # do this $flag = 1; last; } } if (! $flag) { # didn't find it in the array # do the other thing }