my $dbh = DBI->connect("DBI:mysql:database=DATA;..."); my $sth = $dbh->prepare("INSERT INTO DATA VALUES(?, ?)"); foreach my $key (keys %hash1) { # check other hash $sth->execute($data1, $data2); }