my $table = "foo"; my $sql = "SELECT COUNT(*) FROM $table"; my $sth = $dbh->prepare($sql); $sth->execute; my ($count) = $sth->fetchrow_array; if ($count) { print "$table has $count rows!\n"; } else { print "$table is empty\n"; }