in reply to regex with arrays and variables
my $regex = "("; foreach (@array2) { $regex .= $_ . "|"; } $regex .= ")";
You're nearly there. The problem with this code is that it produces something like (foo|bar|quox|), and the trailing pipe symbol makes the empty string match. To fix that, use
my $regex = join '|', @array2;
If you don't want regex meta characters in @array2 to act specially, you should even write
my $regex = join '|', map quotemeta, @array2;
|
|---|