Appears the other posts have the answers, but i would also suggest using
DBI,
DBD::mysql and
DBI Placeholders ...that way the mysql loading can be done at the same time as the parsing. Just a thought.
i had a memory leak once, and it ruined my favorite shirt.