in reply to large number of placeholders

Have you tried:

print $temp;

?

That will probably help you out. Look at the output and you'll probably find that you have a value which is empty and therefore resulting into two consecutive commas (or perhaps a comma next to a bracket), or maybe something similar...

Another thing you could try would be:

use Data::Dumper; print Dumper \%prophash;

Just to see if everything's as expected... but I suspect the print $temp will probably give the error away...

Anyway, I think you should use placeholders instead of constructing the queries yourself... your program will be much safer that way...