in reply to Tell whether two strings differ at only one position

sub compare { (my $xor=$_[0]^$_[1]) =~ tr/\0//d; length $xor < 2; }
Untested. And not benchmarked. But that would be my first try at doing what you need.