Another way is to change the default list separator to the pipe symbol and interpolate the array into a compiled regular expression.
my @titles = qw{ Mr Mrs Ms Miss Dr Sir Lord Lady }; my $titlesRegex = do{ local $" = q{|}; qr{^(@titles)\s+(.*)} }; if( $text =~ $titlesRegex ) { print qq{$1 => $2\n}; }
Cheers,
JohnGG
In reply to Re: Array within regexp?
by johngg
in thread Array within regexp?
by jfrm
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |