my @group1 = ('A','B','C','D'); my $char_class1 = join "", @group1; my $string="DEABCDGHEF"; print "Match: $1\n" while $string =~ /([$char_class]{4})/g;