in reply to Re^3: Regular expression help: why does this not match?
in thread Regular expression help: why does this not match?
Without the grouping there will be strange things happening ;-). Apart from that, depending on the situation, you might want to replace $ at the end of the regex with \z depending on whether you want to allow newlines behind the valid items (your solution) or not (\z).
my $valid_re = qr/^(?:$valid)$/;
Update: To see the strange things happening, try
and all of the inputs will produce okay.
my @valid = qw/foo bar baz/;
my @a_bunch_of_inputs = qw/fooZZZ ZZbarZZ ZZZbaz foobaz foo bar baz/;
Code written by Hofmator and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.