in reply to How to cut down the running time of my program?

Trivial using a database

SELECT * FROM File1 WHERE id IN ( SELECT id FROM File2 )

But really, it's also trivial using Perl.

  1. Load ids from second file into a hash
  2. For each record of File1,
    1. Extract the id,
    2. If the id is in the hash from the second file,
      1. Print the record.

Either way, you read and process each line of the first file once, not once per line in the second file.