in reply to String matching idea

My idea: xor the strings, find the position of the first non-null character in the result.

Update: no code was requested, so using the spoiler tag:

my $xor = $s1 ^ $s2; $xor =~ /[^\0]/g; my $prefix_length = pos($xor) - 1;

If your strings only contain "a" and "b", you can use

index $s1 ^ $s2, "\03"

directly, because "\03" eq ('a' ^ 'b').

لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ