my $sth=$dbh->prepare("SELECT Email FROM foo "); $sth->execute(); while (my $email=$sth->fetchrow_array ) { if ($email=""){ print "Database is empty"; } else { print $email; } } $sth->finish;