First iterate through the PDB file
For each PDB file in list
Read each atom
If it is a Donor or Acceptor, store in list
For each Donor
For each Acceptor
If there is an H-bond, store Atom IDs and labels of the D/A pair in H-bond list
For each H-bond
For each other H-bond
If the nodes of two different bonds are in the same
residue, add a "covalent" bond to list
For each Bond
Add both bonded nodes to hash of unique nodes
Hey! You just described the algorithm you want to use in pseudo-code. From here you only need to translate all the "for each" into a "for(...)" in perl, "if"s into "if (...)", etc.
If it just was that easy ;) Of course the perlcode for e.g. "If there is an H-bond" involves parsing the PDB file. I believe there were several questions about PDB parsing here, but I don't know if any solved this problem.
You are right, Michael. After the question has now been reformatted, it is clear that some parts -- such as "if there is an H-bond" -- are not as trivial as I first thought. I did not spot that beforehand.