my $_startingAmount = sprintf('%.2f', $fileparts [$_checkAmt]); my @potids = (); my $sth = $dbh->prepare(qq{SELECT * FROM `pot` WHERE `adpid` = ? AND `status` = "preissue" ORDER BYE `potid`}); $sth->execute($fileparts[$_emp_id]); while(my $_pot = $sth->fetchrow_hashref()) { if(sprintf('%.2f', $_pot->{amount}) <= $_startingAmount) { push(@potids, $_pot->{potid}); $_startingAmount -= $_pot->{amount}; last if $_startingAmount == 0.00; } next; } $sth->finish(); ## Now go update all the potid records in a foreach statement in @potids