Assuming this is homework, and further to AnonyMonk's comment "This logic is akin to NXOR ie equality" above, consider the stringwise xor of two strings of equal length in which some characters at corresponding positions are the same and some are not.
c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le
"my $m = ' 0 1 0 1';
my $p = ' 0 0 1 1';
;;
my $x = $m ^ $p;
dd $x;
"
"\0\0\0\1\0\1\0\0"
A "\0" character (\000 octal, 0x00 hex) is produced in the resultant string at each position where the characters in the two input strings are the same. (Note that there are three different characters in the example input strings: space, '0' and '1'.) Something other than a "\0" character is produced everywhere else.
The resultant string can then be analyzed by a regex to pick out sequences of "\0" characters that indicate regions of equality between the two input strings. This is the "traditional" way to quickly compare two strings of the same length for position-by-position | for regions of position-to-position equality/inequality. I would build my solution on this string-xor property: look for pairs of strings in which the ' 0 1 0 0 1 1' regions at the ends of each string are the same.
Like u65, I have a solution that I am reluctant to post because of the homeworkish odor of the OP. Please show some more work, or convincing evidence that you are totally stuck for a way forward.
Update: Clarification to this reply made in response to private query by GotToBTru.
Give a man a fish: <%-{-{-{-<
|