in reply to Comparing specific columns from 2 files

Hi arunsriniv. You've already been given suggestions about how to accomplish your goal. What you have is not the right way to go about it. But here are some comments on the code you posted.

First, you should always place

use strict; use warnings;

at the top of your program. This tells Perl to point out errors in your code before it even runs. In your case you are not declaring your variables within the scope they are used in, which makes them global. This is bad practice.

You correctly execute chomp() on $cur_data within the inner loop, but you don't need to chomp( $org_data ) each time; that should be in the outer loop. It's best to chomp() lines from a file as you read them.

It would be better to read in the lines from the original file (and store them in a hash as others have said), and then read the current file in one line at a time, chomp()ing and comparing as you go. No need to put all the lines in an array and no need for a flag; just print an error and call last() or die() or whatever when a comparison fails.

The way forward always starts with a minimal test.