in reply to compare columns in all possible combination

I don't understand your task description and sorry your code is too ugly to be easily understood.

But its certainly not a good idea to read <AB> again and again in a loop processing the lines in <BC> (i.e. @file ).

So put the <AB> stuff into an initialization part populating @coll just once, that is before looping.

Cheers Rolf

(addicted to the Perl Programming Language and ☆☆☆☆ :)