<?xml version="1.0" encoding="windows-1252"?>
<node id="140627" title="Re: Matching bits of 2 strings" created="2002-01-22 08:49:43" updated="2005-07-21 01:30:39">
<type id="11">
note</type>
<author id="961">
Anonymous Monk</author>
<data>
<field name="doctext">
My solution to the problem isn't as compact as the other solutions, but TIMTOWTDI!

&lt;code&gt;
#! /usr/local/bin/perl

$string1 = "the date is today";
$string2 = "the date is tomorrow";

$concat = $string1 . "#" . $string2;

if ( $concat =~ m/^(.*)(.*)#\1(.*)$/ ) {
    print "matching part: $1\n";
    print "difference: $2\ndifference: $3\n";
} else {
    print "strings $string1 and $string2 do not match!\n";
}
&lt;/code&gt;

When run it generates the following output

&lt;code&gt;
matching part: the date is to
difference: day
difference: morrow
&lt;/code&gt;

I have to note that this solutions uses the fact dat the to strings doesn't contain any poundsymbols (#). When one of the to strings contain a poundsymbol, you have to use another symbol(sequence) to, for example:

&lt;code&gt;
...
$concat = $string1 . "#!!#" . $string2;

if ( $concat =~ m/^(.*)(.*)#!!#\1(.*)$/ ) {
...
&lt;/code&gt;

I hope that this will give you a hint to construct your own solution!</field>
<field name="root_node">
140538</field>
<field name="parent_node">
140538</field>
<field name="reputation">
44</field>
</data>
</node>
