foreach my $audit (keys(%$audits)) { $query = q{ ... ); my $sth = $dbh->prepare($query); sth->execute($audit); ...