#!/usr/bin/perl my %k; # hash to hold infinitives and their other parts process( 'thirdperson', 'file1'); process( 'past', 'file2'); for (keys %k){ if( $k{$_}{thirdperson} and $k{$_}{past} ){ print "$_\t$k{$_}{thirdperson}\t$k{$_}{past}\n"; } } sub process { my $part = shift; my $filename = shift; open my $fn, '<', $filename or die $!; while(<$fn>){ chomp; my($other, $infinitive) = split /\t/; $k{$infinitive}{$part} = $other; } close $fn; } #### sort -k2 -o file1 file1 sort -k2 -o file2 file2 join -j 2 -t ' ' file1 file2 # inserted a tab between the quotes with Ctrl-V