This is actually a very difficult problem, because a given compound may exist in multiple conformations (have multiple structures), and it might not be obvious what conformation is most relevant.
For example, a seemingly simple compound like glucose has multiple stereoisomers: if you say "glucose", you probably mean alpha-D-glucose, as opposed to beta-D-glucose, or even L-glucose. But a PDB structure file may not specify the stereochemistry to this level, or ignore it completely, and then you have no way of knowing what compound was intended. Conversely, sometimes a specific structure is given, like this open form of D-glucose; but in a water solution this structure spontaneously interconverts with the closed ring form (they are tautomers). And there are other problems with protonation (which depends on solvent and pH), charge distribution, and what not. Chemistry is a mess :)
To sum it up, the fundamental problem is that more than one completely distinct structure can actually represent the same physical compound. Therefore, comparing physical compounds is difficult; it depends on the level of detail of specification you want. I don't think there is a generic solution for this.
Comparing structures, on the other hand, is perfectly feasible: I would recommend you take a look at the InChi format developed by IUPAC. It is an identifier string that uniquely identifies a molecular structure, so testing for structural identity is equivalent to simply comparing the corresponding InChi strings. The PDB has InChi strings associated with its entries, so this should be straightforward. (But again, this simple procedure will conclude that, for example, the open form and the closed-ring form of glucose are different things.)
I'm not sure about the atom numbering. The InChi format determines atom numbering in some canonical way according to predefined rules, so in this representation the numbering is by definition always the same (and therefore meaningless). But you would need to look into the details of the PDB--InChi conversion procedure to determine which atom gets mapped to which.