Hi,
I recommend you using pdsh
In your case should be:
modify your script to receive only database name as parameter (and to make only the work needed to that database), databases file contains line by line all the databases
$ pdsh -w^databases -R exec perl-script %h | tee outputs
then play with outputs (see dshbak), probably with an script which recollect the info