in reply to Not sure how to query my database in this code
Please forgive the not-so-perfect alignment, haven't gotten around to cleaning it up yet.
Perltidy can help you with that.
HTH,