in reply to Best Pairs

One 'efficient' algorithm I can think of -

Presteps:
Step 1 - build a hash that holds the combination pairs of 1..N (math notation N C 2) as search keys, values initialized to 0.
Step 2 - while iterating through the input lines/arrays, for each combination of the elements on the current line, increment value of $hash{$comb_idx} by 1.

The aim of the prestep is to reduce the data set you have to work with (N=20, number of pair-combinations is just 190). The result hash will contain a count of the combinations in the data set. The hash key can be, simply, $n1 . '-' . $n2. Eg., '1-6', '3-18', etc.

Poststeps:
Step 1. For the given element, build a new hash by grepping for the given element in the keys of the original hash, and assigning the key=>count in the hash.
Step 2. Sort this hash to find the hash key for the top N counts, and decode the hash keys to get the other numbers in the pair.

The beauty of this solution is that once the hash of pair-combination-count is built (in the initialization phase), looking for 'maximum pairs' would be lightening fast.

I can implement the above algorithm in Perl later, but I think it should be piece of cake for you, besides, you are only looking for an algorithm afterall.

:-)