use Regexp::List qw( ) my $re = Regexp::List->new->list2re(@B_CHECKS); $re = qr/^(?:0|5|6)0+($re)$/; for my $cn ( @CS_CHECKS ) { if ( $cn =~ $re ) { print "$1 = $cn\n"; } }