lock_db_tables(); # lock tables and/or start a transaction # in a database independent way # some preparation that requires a database lock my $firsttime = 1; foreach my $id (@list_o_object_ids) { lock_db_tables() unless $firsttime; $firsttime = 0; my $obj = new Thingy($id); # gets stuff from db # make changes, save back to db. unlock_tables(); }