my $sql = "SELECT ID FROM User WHERE Status = 'X';"; my $sth = $dbh->prepare($sql); $sth->execute; while ( my $id = $sth->fetchrow_array ) { $dbh->do("DELETE FROM User WHERE ID = $id;"); }