in reply to Default variable within loops
Three things:
-
The reason you find that you need to use $temp is that you the $_ associated with the grep is referring to an element of @b, not @a.
-
The reason you are getting a count instead of the actual matches is that you are assigning the results to a scalar, not an array.
-
One more thing... I believe you are testing for equivalency instead of checking for a pattern match. If you want to perform a typical grep, maybe use something like grep( $temp =~ /$_/, @b )