Some thoughts on various modules to do some/all of the work for you:
Could use
DBD::CSV to read the source tables .. or use something like
DBIx::Copy with it to do everything in one shot.
For the just-generate-the-sql method,
SQL::Abstract is a handy module ..
It might also be possible w/
DBD::AnyData to do it with a single cross-db SQL statement (not sure if they both need to by in-memory tables or not):
INSERT INTO db_table ( col1, col2, col3 )
SELECT colA, colB, colC
FROM csv_table
;