If you can use Perl version 5.10, then there is a really easy way to do this. Just use the new smart match statement (~~) .
use warnings;
use strict;
use 5.10.1;
my @matches = (
qr/.*\.so$/,
qr/.*_mdb\.v$/,
qr/.*daidir/,
qr/\.__solver_cache__/,
qr/csrc/,
qr/csrc\.vmc/,
qr/gensimv/,
);
if( $_ ~~ @matches ){
...
}
If you cannot use Perl 5.10, I would use List :: MoreUtils :: any .
use warnings;
use strict;
use List::MoreUtils qw'any';
my @matches = (
);
my $test = $_;
if( any { $test =~ $_ } @matches ){
...
}
source
share