my $sth1 = $db->prepare(q{ UPDATE trees SET department = ? WHERE sport = ? AND round = ? }) or die "Can't prepare first statement: ". $dbh->errstr() . "\n"; # and so with $sth2 and $sth3 # execution time for my $i (1..13) { # I'd suggest reworking this data structure too, but # I'll work with what you have # smaller sermon : initialize the variables that are # expected to change on each step through the loop # with my *** inside the loop *** # that way, you get a fresh copy of the variable each time # through without potentially having old values intrude my $team = $teams{"team$i"}; my $score = $scores{"score$i'}; $sth1->execute ($team, $sport, $i) or die "Execution of first update failed: ". $dbh->errstr() ."\n"; $sth2->execute( #blah blah... }