in reply to Re^3: add elements to array at certain positions
in thread add elements to array at certain positions

Oops, I'm sorry! I will stop posting at night before sleep. Here is a fast List::MoreUtils alternative that actually does what the OP asks for this time:

use List::MoreUtils qw(indexes); my $a = '0157953'; my $b = 'abcyefzaa'; my $new = $a; substr $new, $_, 0, 'I' foreach ( indexes { $_ =~ /^[yz]$/ } split(//, $b) ); print $new, "\n";

Update: I just realized this nearly identical loop is much faster (nested update: oops it's pos-1):

substr $new, pos($b)-1, 0, 'I' while ( $b =~ /[yz]/g );