#!/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; }