sub compatible { my ($s1, $s2) = @_; my %hashed; my $diff = 0; my ($one, $two); my @counts; my $n = 10; # # Hash so that each $s1 value is a key with its corresponding # $s2 value as the hashed value. # @hashed{map {($_ eq '_') ? $n++ : $_} split("", $s1)} = map {($_ eq '_') ? $n++ : $_} split("", $s2); # # Compare each $s1->$s2 pair # while (($one, $two) = each %hashed) { next if ($one == $two); last if (($diff = (++$counts[$one] - 1)) > 0); last if (($diff = (++$counts[$two] - 1)) > 0); $diff = 0; next if ( ($one >= 10) || ($two >= 10) ); last if (($diff = ($one - $two)) != 0); } print "$s1\n$s2\n", ($diff == 0) ? "compatible" : "incompatible", "\n\n"; }