Something like this should do the trick:
Check into placeholders and bind values. That will make writing your queries a little easier. Here's a link to that section in the DBI pod:
http://search.cpan.org/~timb/DBI-1.3...nd_Bind_Values. It takes a bit to get used to them at first but it's worth it. Also, see me comments in the script for a little more detail.
Check out the perl quote operators too:
http://www.perldoc.com/perl5.8.0/pod/func/q.html. Not much of an explanation there but
q{tetxt} single quotes the text in side the {}. That satement above would be 'text'. The
qq{text} is for double quotes: "text". The {} is arbitrary; you can use anything as long as it's not in the string to be quoted: () or [] or !! or $$ and the list goes on. I often ues the
~ in my queries:
qq~SELECT foo FROM bar~;. This eliminates the need to escape any quote chars in your queries.
~Charlie