# Read header file and store it in hash open(FILE,"header.txt"); while(){ chomp; next if (/^\s*$/); my @fields = split(/\,/,$_); push(@{$hashkeys{$fields[0]}{fields}},$fields[4]); # Iam pushing all headers for each table i.e. for field[0] into hash array } CLOSE FILE; # open file1 and file2 and readthem into Hashes %hash1 and %hash2 as below open FILE,"file1"; while ( ){ my @arr = split ( /\,/,$_ ); my $key = join("-->",@arr); $hash1{$key} = 1; } # llly for file2 i.e. %hash2 contains above. # The below arrays gives me lines which are different my @missing1 = grep ! exists $hash1{ $_ }, keys %hash2; my @missing2 = grep ! exists $hash2{ $_ }, keys %hash1; # now iam reformatting the arrays w.r.t header file # Now i want to show output as below.. # Cols which are different in file1 00240 00020 00090 00690 01040 00241 00243 00710 00242 1 2 4 8 # Similarly for file2 # i have done it in lengthy way , with no luck and no formatting