my %found; ## instead of my $found = {}; ... unless ( ($p1 == $p2) || $found{ "$p2|$p1" } ) { ... $found->{ "$p1|$p2" } = 1;