but through every possible residue pair (though not residues in the same chain of course) and seeing if they are close enough
Probably a stupid question, and not perl related, but why not look at interactions from the same chain? Surely they are as important as inter-chain interactions?