<?xml version="1.0" encoding="windows-1252"?>
<node id="140538" title="Matching bits of 2 strings" created="2002-01-21 23:09:17" updated="2005-08-13 12:15:57">
<type id="115">
perlquestion</type>
<author id="140528">
m2</author>
<data>
<keywords>
<keyword rating="">
binary</keyword>
</keywords>
<field name="doctext">
Hiyas :)

Here's the situation: I have many pairs of 2 strings that may (or may not) match each other from the beginning up to a certain point, then become different. What's the "best" (efficient, clean, etc) way of determining 1). the matching parts of the two strings 2). the part of each that's different?
&lt;BR&gt;i.e. for:
&lt;code&gt;
$string1 = "the date is today";
$string2 = "the date is tomorrow";
&lt;/code&gt;
I want:
&lt;code&gt;
$matchingpart = "the date is to"
$diff1 = "day"
$diff2 = "morrow"
&lt;/code&gt;
It isn't hard to iterate over the first string letter by letter and do comparison to the second, but it really seems like there should be a more... elegant solution.  Any ideas?
&lt;BR&gt;
Regards,
&lt;BR&gt;m2.</field>
</data>
</node>
