5 6 9 2 3 4 1 3 4 1 2 4 1 2 3 #### $regex .= '(?{ print join(" ", map $$_, 1..$k), "\\n" })(?!)'; $string =~ /$regex/x; #### push @string, $string;