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

The method demonstrated below is devious and should be avoided in favour of something more conventional.

my $stra = '0157953'; my $strb = 'abcyefzaa'; (my $new = $strb) =~ s/([yz])|./ (defined($1) ? 'I' : ($stra =~ m{(.)}sgc ? $1 : die ) ) /seg; print("$new\n"); # 015I79I53

Update: Saner: (no nesting)

my $stra = '0157953'; my $strb = 'abcyefzaa'; my $new = ''; while ($strb =~ /([yz])|./sg) { $new .= (defined($1) ? 'I' : ($stra =~ /(.)/sgc ? $1 : die ) ); } print("$new\n"); # 015I79I53