EDIT:added \D around the variable in the REGEX after smoss's response. That should take care of the extra elements your were getting. The way it was before it would pick out 96 in the string if one of the numbers was either 9 or 6, adding the non number boundary should force it to match numbers exactly. It works on my tests. If it still doesn't work for you give me your sample data and I'll see if I can recreate the problem.foreach $element (@a) { foreach $number (@b) { if ($element =~ /\D$number\D/) { push (@c, $element); } } }
In reply to Re: comparing element in arrays
by Cyrnus
in thread comparing element in arrays
by smoss
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |