This seems to work:

=IF(A1=B1,4,IF(LEFT(A1,3)=LEFT(B1,3),3,IF(LEFT(A1,2)=LEFT(B1,2),2,IF(LEFT(A1)=LEFT(B1),1,0))))

Hope this helps.

Pete