in reply to Mostly Harmless
A single hash (and a couple of temporary hashes) cleans up the code somewhat at the cost of a higher degree of Perl knowledge for understanding:
use strict; use warnings; my $str1 = 'CHARLIE ROOT'; my $str2 = 'HARRY NODE'; my @chars1 = split '', $str1; my @chars2 = split '', $str2; my %hits; $hits{$_} = 1 for @chars1; ++$hits{$_} for keys {map {$_ => 1} @chars2}; print $_ for grep {$_ eq ' ' || $hits{$_}++ == 1} @chars1, @chars2;
Prints:
CLI TY ND
|
|---|