use strict; sub compatible { my ($s1, $s2) = @_; my %hashed; my $diff = 0; my ($one, $two); # # Hash so that each $s1 value is a key with its corresponding # $s2 value as the hashed value. # @hashed{split("", $s1)} = split("", $s2); # # Compare each $s1->$s2 pair # while (($one, $two) = each %hashed) { next if ( ($one eq '_') || ($two eq '_') ); last if (($diff = ($one - $two)) != 0); } print "$s1\n$s2\n", ($diff == 0) ? "compatible" : "incompatible", "\n\n"; } my @tests = (qw/ _8__3__19 48____7__ _8__3__19 4_2___7__ _8__3__19 4_8___7__ __8_3__19 48____7__ __8_3__19 84____7__ _8__3__19 48_____7_ / ); my ($s1, $s2); while (defined($s1 = shift(@tests))) { $s2 = shift(@tests); compatible($s1, $s2); }