in reply to compare initial

I still don't really understand what you want from the OPed code, but here's an approach that produces the same result and which may (or may not) be considered "neater." I've made no attempt to Benchmark this code. Note that the strings need not all be the same length. Also, a  '0' character (which tests false) is handled properly.

c:\@Work\Perl\monks>perl -wMstrict -le "my $x = 'TTT0TTTTT'; my $y = 'TTTTTTTT'; my $z = 'TBTTTTT'; ;; print qq{only one of '$_'} for one_only($x, $y, $z); ;; sub one_only { my %freq; return grep $freq{$_} == 1, map ++$freq{$_} && $_, map split('', $_), @_ ; } " only one of '0' only one of 'B'

Update: Actually, here's an equivalent variation based on substr that might actually be significantly faster than split-ing every string into countless characters. (Again, I haven't Benchmark-ed.)

c:\@Work\Perl\monks>perl -wMstrict -le "use Test::More 'no_plan'; use Test::NoWarnings; ;; for my $ar_vector ( [ [], ], [ [], '' ], [ [], '', '' ], [ [], '', '', '' ], [ [ 'A' ], 'A' ], [ [], qw(A A) ], [ [], qw(AA) ], [ [], qw(A A +A) ], [ [ qw(A B) ], qw(A B) ], [ [ qw(A B C) ], qw(A B C) ], [ [ qw(A B C D E F G H) ], 'HGFE', 'ABCD' ], [ [ qw(A B C D E F G H I) ], 'GFED', 'HI', 'ABC' ], [ [], 'TTTTTTT', 'TTTTTTTTT' ], [ [ 'A' ], 'TTTATTTT', 'TTTTTTT' ], [ [ qw(A B) ], 'TBTTTTT', 'TTTATTT' ], [ [ qw(A B) ], 'TTTTTTA', 'TTTTTTB' ], ) { my ($ar_expected_singletons, @strings) = @$ar_vector; ;; my $strings_cmnt = qq{@{[ map qq{'$_'}, @strings ]}}; ;; my @got_singletons = singletons(@strings); is_deeply \@got_singletons, $ar_expected_singletons, qq{($strings_cmnt) singleton(s): (@$ar_expected_singletons)}; } ;; done_testing; ;; exit; ;; sub singletons { my %freq; for (@_) { for my $o (0 .. length($_)-1) { ++$freq{substr $_, $o, 1} } }; return sort grep $freq{$_} == 1, keys %freq; } " ok 1 - () singleton(s): () ok 2 - ('') singleton(s): () ok 3 - ('' '') singleton(s): () ok 4 - ('' '' '') singleton(s): () ok 5 - ('A') singleton(s): (A) ok 6 - ('A' 'A') singleton(s): () ok 7 - ('AA') singleton(s): () ok 8 - ('A' 'A' 'A') singleton(s): () ok 9 - ('A' 'B') singleton(s): (A B) ok 10 - ('A' 'B' 'C') singleton(s): (A B C) ok 11 - ('HGFE' 'ABCD') singleton(s): (A B C D E F G H) ok 12 - ('GFED' 'HI' 'ABC') singleton(s): (A B C D E F G H I) ok 13 - ('TTTTTTT' 'TTTTTTTTT') singleton(s): () ok 14 - ('TTTATTTT' 'TTTTTTT') singleton(s): (A) ok 15 - ('TBTTTTT' 'TTTATTT') singleton(s): (A B) ok 16 - ('TTTTTTA' 'TTTTTTB') singleton(s): (A B) 1..16 ok 17 - no warnings 1..17


Give a man a fish:  <%-{-{-{-<