my %file1hash; open (DAT1,"$fin1"); while(my $line=) { chomp($line); my ($id,$x1,$x2)=split(' ' ,$line); $file1hash{$id} = "$x1 $x2"; } close DAT1; open (DAT2,"$fin2"); while (my $line=) { chomp($line); my ($id,$word)=split(' ', $line); if (exists $file1hash{$id}) { printf ("%1s %5s %7s\n", $id, $file1hash{$id}, $word); } } close DAT2; exit;