lock_db_tables(); # lock tables and/or start a transaction # in a database independent way # 1100 lines of preparation that requires a database lock # must be in same transaction as first iteration of loop # below foreach my $id (@list_o_object_ids) { my $obj = new Thingy($id); # gets stuff from db # make changes, save back to db. (about 900 lines in my case) unlock_tables(); } join { lock_db_tables(); }