my $found = 0; while(my @row = $sth->fetchrow_array) { ++$found; ... process @row ... } if(!$found) { ... no rows found ... }