Check out the Bioconductor case studies book (By Florian Hahne, Wolfgang Huber, Robert Gentleman, Seth Falcon). There's a whole chapter about this. The code is also available online. It will save you lots of time...
Re^3: BioPerl: Best Gene Ontology API
Replies are listed 'Best First'.