Is there any reason why you can't use the prepare_cached provided by DBI?
In reply to Re: DBI prepare and function recursion by adrianh in thread DBI prepare and function recursion by simon.proctor