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/ ); } #### 3: 5 : E 13: 1 : A 15: 3 : C 19: 3 : C 26: 1 : A 35: 5 : E 39: 5 : E 42: 5 : E 44: 5 : E 53: 5 : E 73: 1 : A 75: 1 : A 81: 12 : L 83: 5 : E