note
LanX
please use real <c><code></c> tags and not <c><code></c><P><P>
looks like you want the [wp://symmetric difference] of two character sets<P><P>
<c>
DB<111> @a1=split//,$str1
=> ("A", "B", "C", "D", "E")
DB<112> @a2=split//,$str2
=> ("B", "C", "D", "E", "O")
DB<113> @h2{@a2}=()
DB<114> @h1{@a1}=()
DB<115> delete @h2{@a1}
DB<116> delete @h1{@a2}
DB<117> (keys %h1, keys %h2)
=> ("A", "O")
</c><P><P>
see [id://906065] for background.<P><P>
<H5> UPDATE: <P></H5><P>
seems like nobody mentioned that its a FAQ [doc://perlfaq4#How-do-I-compute-the-difference-of-two-arrays?-How-do-I-compute-the-intersection-of-two-arrays?]<P><P>
<H5> UPDATE:<P></H5><P>
Just in case you only want the unique characters in both strings:<P><P>
<c>
DB<137> $h{$_}++ for (split//,$str1),(split//,$str2)
=> ""
DB<138> \%h
=> { A => 1, B => 2, C => 2, D => 2, E => 2, O => 1 }
DB<139> grep {$h{$_}==1} keys %h
=> ("A", "O")
</c><P><P>
oops basically already [id://1016856|shown] by [Not_a_Number]<P><P>
EDIT: one liner =)
<c>
DB<146> grep {$h{$_}==1} map {$h{$_}++;$_} split//,$str1.$str2
=> ("A", "O")
</c><P><P>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-708738">
<p>Cheers Rolf
</div></div>
1016850
1016850