#!/bin/usr/perl use strict; use warnings; use Text::csv; my $csv_keys = <new(); open my $keysIn, '<', \$csv_keys; while (my $row = $csv->getline($keysIn) ) { for my $cellNum (1 .. @$row) { $keys{$cellNum}{$row->[$cellNum - 1]} = $.; } } close $keysIn; open my $phrasesIn, '<', \$csv_phrases; while (my $row = $csv->getline($phrasesIn) ) { for my $cellNum (1 .. @$row) { for my $key (keys %{$keys{$cellNum}}) { next if $row->[$cellNum - 1] !~ /\Q$key\E/; print <## Matched 'blue' in cell 1 from keys line 1 to phrases line 1 Matched 'sun' in cell 3 from keys line 2 to phrases line 1 Matched 'red' in cell 1 from keys line 2 to phrases line 2