in reply to match text files

Here is my outline:

  1. Read one file and split into first element and rest. Create hash with key being the first element.
  2. Read second file line by line. Split into first element and rest.
  3. See whether first element exists in hash. If so print all.
Not tested as i do not have two fitting files at hand.

use strict; use warnings; open (my $fh, "<", "C:/position.txt"); my %position = map { split /\t/, $_, 2 } <$fh>; # not sure about this close($fh); open (my $file, "<", "C:/platform.txt"); open (my $newfile, ">", "C:/result.txt"); foreach my $line (<$file>) { my( $start, $rest ) = split /\t/, $line, 2; print $newfile $start, "\t", $position{$start},"\t", $line if exists + $position{$start}; } close($file); print "DONE";