my ($sth, $row); $dbh = ; $sth = $dbh->prepare (qq{ SELECT * FROM mytable }); $sth->execute(); while ($row = $sth->fetchrow_hashref()) { # these are the rows that do exists do # what you want with those rows. }