in reply to String replacement

This is the same as what you're doing, but using s/// to walk the template.
my $a = "ABABA"; my $b = "BB--B-BB"; my $new = $b; my $a_pos = 0; $new =~ s:[^-]:substr($a, $a_pos++, 1):ge; print "New is $new\n";
Update: I like this better. Inserting hyphens at corresponding points:
my $a = "ABABA"; my $b = "BB--B-BB"; substr($a, pos($b)-1, 0, '-') while ($b =~ /-/g); print "A is now $a\n";

Caution: Contents may have been coded under pressure.