use Modern::Perl; use Regexp::Assemble; # load the arrays my @cg = ( 1, 5, 12, 3 ); my @gl = map { int( rand 20 ) + 1 } ( 1 .. 100 ); my @csta = map { chr( $_ + 64 ) } @gl; say "@gl\n@csta"; # for debug purposes only # assemble the regex my $ra = Regexp::Assemble->new; $ra->add(@cg)->anchor_word(1)->re; say $ra->as_string; # for debug purposes only # find the matches for my $idx ( keys @gl ) { say "$idx: $gl[$idx] : $csta[$idx]" if ( $gl[$idx] =~ m/$ra/ ); }