my @foo = qw/a b c d e f g/; my $sub = 'h'; for (my @extras = @foo; @extras; @extras = my @new_extras) { foreach my $x (@extras) { push @new_extras, $sub++ if $x =~ /[dhij]/; } push @foo, @new_extras; } print for @foo; # Tacks on h when it hits the d, then # i for the h, j for the i, and k for the j # yielding abcdefghijk