http://www.perlmonks.org?node_id=162038

Superman has asked for the wisdom of the Perl Monks concerning the following question: (strings)

I have 2 strings which should be identical:
$PDBline; $XMLline;
and I test for this normally:
if ($PDBline eq $XMLline){etc...}
However in the event that they dont match I want to do a percentage comparison where I match each word in $PDBline against the words in $XMLline.

So say I want a 75 % similarity between the 2 strings...

my $threshold = 0.75; my $counter = 0; foreach my $word ( split ' ', $PDBline ) { $counter++ if $XMLline =~ /$word/; }
Does this seem right or is there an easier way to do this??

Originally posted as a Categorized Question.