my %sth_cache; for (@$sales_inserts) { my $table = shift(@$_); my $sth = $sth_cache{$table} ||= $dbh->prepare(' INSERT INTO '.$dbh->quote_identifier($table).' ( ItemID, Day, Revenue, Count ) VALUES ( ?, ?, ?, ? ) '); $sth->execute(@$_); }