my @regex_pieces = (); foreach my $permutation (@permutations) { my @vowels = split //, $permutation; push @regex_pieces, join(".*", @vowels); } my $regex = qr/@{[join("|", @regex_pieces)]}/i;