my $a = "ABABA"; my $b = "BB--B-BB"; substr($a, pos($b)-1, 0, '-') while ($b =~ /-/g); print "A is now $a\n";