I have thoughts about using any array_ref as your result set from a DB call, as I like using hashref, but that's another thread. Here's what I'd do: (untested for syntax errors)
my $i = 0;
while ($sth->fetchrow_hashref){$i++;
##..do other stuff..
}
do_your_no_row_stuff($vars) unless $i;