in reply to Smart Comparison of Buffy Strings

Here's the start of another approach, based on using Algorithm::Diff to count the number of common words (in sequence) between two arrays of strings. By computing a percentage based on the smaller of the arrays, you address both the case of the submitted quote being a subset of an existing quote, and vice versa.

Here's how it hands the "gonna" -> "going to" change.

use strict; use Algorithm::Diff qw(traverse_sequences); my @quote1 = split(' ', <<QUOTE); I walk. I talk. I shop, I sneeze. I'm gonna be a fireman when the floods roll back. There's trees in the desert since you moved out. And I don't sleep on a bed of bones. QUOTE my @quote2 = split(' ', <<QUOTE); I'm going to be a fireman when the floods roll back. There's trees in the desert since you moved out. QUOTE my $match = 0; traverse_sequences(\@quote1, \@quote2, { MATCH => sub { $match++ } } ); my $smaller = @quote1 < @quote2 ? @quote1 : @quote2; my $percent_match = int(($match / $smaller) * 100); print "$match words matched ($percent_match%)\n"; __END__ 18 words matched (90%)
To make this work in practice, you would need to do things like ensure that the shorter quote was at least n words long, so that a 1 word candidate quote didn't match at 100%.

A few minutes perusing the Algorithm::Diff POD might give you some additional ideas.