@x = glob('{a,b,c}'x6); $x = '(?:a()|a()|b()|b()|c()|c()){6}\1\2\3\4\5\6'; # limited repeats allowed for $i (@x) { $i =~ $x and say $i; # was $x =~ $i }