This might serve as a starting point.

#! perl -slw use strict; sub genRegex { my $query = shift; $query =~ tr[A-Za-z0-9 ][a-za-z0-9 ]; my @words = split ' ', $query; my $regex = join '\W+'.$/, map{ my $s=''; $s = "(?:$_$s)?" for reverse split ''; chop $s; "\\b$s\\b" } @words; return qr[$regex]xi; } my $regex; while( my $line = <DATA> ) { chomp $line; $regex = genRegex( $1 ) and print'' and next if $line =~ m[search for (.*) should match...]; print +($line =~ $regex ? 'Matched ' : 'Failed ' ), $line; } __DATA__ search for Aetna Insurance Company should match... Aetna Insurance Company Aetna Ins. Co. Aetna Insurance Co. Aetna Ins. Company Aetna Ins Company aetna insurance co Aetna Ins Co Atna Insurance Company Aetna Ins. Ca. Aetna Insurance Go. Aetna Ins. Compary search for Sam Jones should match... Sam Jones Sam J. Jones Sam J Jones S. Jones Samuel Janes Sam L Jones Sam J.J. Jones Sam J Jones B. Jones Manuel Jones

Results:

P:\test>junk Matched Aetna Insurance Company Matched Aetna Ins. Co. Matched Aetna Insurance Co. Matched Aetna Ins. Company Matched Aetna Ins Company Matched aetna insurance co Matched Aetna Ins Co Failed Atna Insurance Company Failed Aetna Ins. Ca. Failed Aetna Insurance Go. Failed Aetna Ins. Compary Matched Sam Jones Matched Sam J. Jones Matched Sam J Jones Matched S. Jones Failed Samuel Janes Failed Sam L Jones Matched Sam J.J. Jones Matched Sam J Jones Failed B. Jones Failed Manuel Jones

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
Hooray!


In reply to Re: Some kind of fuzzy logic. by BrowserUk
in thread Some kind of fuzzy logic. by the_0ne

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.