my $i = 0; while ($sth->fetchrow_hashref){$i++; ##..do other stuff.. } do_your_no_row_stuff($vars) unless $i; #### do_no_row_stuff() unless $sth->fetchrow_hashref; ## Of course, the first row is now useless.. but..