open(FILE1, "file1"); open(FILE2, "file2"); while(){ /(\S*)\s+(\S*)/; $hash{$1}=$2; } while(){ /(\S*)\s+(\S*)/; print "$1 $hash{$1} $2\n" if $hash{$1} }