Does it need to be a regex? If you can live with an exact match, then I'd use a hash:
my %want_global = map { ($_ => 1) } qw(
THIS
THAT
ANOTHER
);
...
if ( $want_global{$global} ) {
...
}
If you really need to have regexes, then put them in an array instead of a single regex, it will generally perform better than a joined single regex (and put the most likely things to match first, if possible):
my @wanted_re = (
qr/^AB/,
qr/^CD/,
);
sub want_global {
my $g = shift;
for my $re (@wanted_re) {
return 1 if $g =~ /$re/;
}
return;
}
Update: I see that maybe you want 'unwanted global' logic...whatever...the above still applies...adjust to suit needs.