$dbh->begin_work; my $channel = $dbh->selectrow_hashref("SELECT * FROM data WHERE ToScan IS NULL AND title IS NOT NULL limit 1 FOR UPDATE SKIP LOCKED"); my $ID = $channel->{'id'}; my $title = $channel->{'title'}; # $dbh->do returns the number of rows affected on success or undef # on failure, so you need to use defined-or (//) here instead of a # regular or (||) unless you want "zero rows affected" to be # treated as a fatal error. if (defined $ID) { $dbh->do("UPDATE data SET lock=1 WHERE id=?", undef, $ID) // die $rsth->errstr; } $dbh->commit;