in reply to Optimizing File handling operations

if both files are huge creating large sized arrays may consume lot of memory.
That is indeed true, but memory is cheap and as long as you are not running out of memory there is nothing wrong with your approach.

However, if you are running into a lack of memory, then just open the two files at the same time and read them line by line:

use strict; use warnings; open my $first_file, '<', '/my/first/file'; open my $second_file, '<', '/my/second/file'; while (my $line_first = <$first_file>) { my $line_second = <$second_file>; # do something with $line_first and $line_second # ... }
This will work if both files have the same length or /my/first/file has more lines than /my/second/file. If not you will have to put in some extra tests.

And of course, you will want to check if the open succeeded!

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James