#!/bin/perl my @csv2 = (); open CSV2, "; close CSV2; my %csv2hash = (); for (@csv2) { chomp; my ($title) = $_ =~ /^.+?,\s*([^,]+?),/; #/ match the title $csv2hash{$_} = $title; } open CSV1, ") { chomp; my ($title) = $_ =~ /^.+?,\s*([^,]+?),/; #/ match the title my %words; $words{$_}++ for split /\s+/, $title; #/ get words ## Collect unique words my @titlewords = keys(%words); my @new; #add exception words which shouldn't be matched foreach my $t (@titlewords){ push(@new, $t) if $t !~ /^(rare|vol|volume|issue|double|magazine|mag)$/i; } @titlewords = @new; my $desired = 5; my $matched = 0; foreach my $csv2 (keys %csv2hash) { my $count = 0; my $value = $csv2hash{$csv2}; foreach my $word (@titlewords) { my @matches = ( $value=~/\b$word\b/ig ); my $numIncsv2 = scalar(@matches); @matches = ( $title=~/\b$word\b/ig ); my $numIncsv1 = scalar(@matches); ++$count if $value =~ /\b$word\b/i; if ($count >= $desired || ($numIncsv1 >= $desired && $numIncsv2 >= $desired)) { $count = $desired+1; last; } } if ($count >= $desired) { print "$csv2\n"; ++$matched; } } print "$_\n\n" if $matched; } close CSV1;