my $merged=""; map{ $merged .= $_ if( $merged !~/\Q$_\E/ ) } split(//, $string1.$string2);