in reply to Searching for best match

Wow, looks like perl is too clever for its own good. You feed it the string "Reuel T" and it magically translates it to "R Tolkien". Now that's DWIM taken too far!

Beside that inconsistency between your input and the output you say you have, your exemple does not illustrate well what you meant by "best match", because in all cases the search string is fully contained in one of the sources. ("John Ronald Reuel T" and "<John Ronald Reuel T>olkien"). If your original search string was indeed "John Ronald R Tolkien", I suppose you'd still want to match "John Ronald Reuel Tolkien"?

And FYI, you can do all this:

#gets first two names (my $twonames=$s)=~s/^(\w+ \w+).*$/$1/; #gets all other names, if they exist (my $others=$s)=~s/^(\w+ \w+)//; #deletes initial space (my $alternativesearch=$others)=~s/^\s//;
in one line (see "matching in list context" in Quote and Quote like Operators): my ($twonames, $others) = /^(\w+ \w+)(?: (.+))?/;

Replies are listed 'Best First'.
Re^2: Searching for best match
by Sosi (Sexton) on Oct 06, 2014 at 12:54 UTC

    eh I missed that upon editing my post. Thanks, I edited it accordingly.

    Regarding the "best" match, I am looking for the match that differs less. This would be the match that would contain the most characters. I am now looking into the smallest distance between sentences using Text::Fuzzy, but I'll have a look at those modules that Anonymous Monk posted above. Also, thanks for your tip on the one line assignment. I guess this just shows how "green" I am :( Thank you!