use strict; use warnings; use v5.10; my @data = <>; my $match_count = 1; foreach my $line (@data) { chomp ($line); print "Processing line [$line]\n"; $line =~ s/[",\/-]/ /g; # Change all potential word endings to a single space $line =~ s/[()]//g; # Remove parentheses to avoid mishaps during pattern matching my ($id, $source, $comparison) = split "\t", $line; # Split columns into an array foreach my $word (split ' ', $source) { given (length $word) { when ($_ < 3) { next; } when ($_ < 5) { if ($comparison =~ /$word/i) { print "Match [$match_count] (probable): [$word]\n"; $match_count++; } } default { if ($comparison =~ /$word/i) { print "Match [$match_count]: [$word]\n"; $match_count++; } } } } }