When there are more than one possibilities of merging like below. We take the "last" merge. my $str3 = 'ATGATG'; my $str4 = 'ATGATG'; $merged_result34 = 'ATGATGATG';