use strict; use warnings; my @group1 = ('A','B','C','D'); my @group2 = ('E','F','G','H'); my $string="DEABCDGHEF"; local $" = ''; print "Match: $1\n" while $string =~ /([@{[@group1[0..2],@group2[2,3]]}]{5})/g;