$sth = $dbh->prepare("select count(distinct all_id) as a from users") or die ("Error in SQL\n"); $sth->execute(); my $counts = $sth->fetchrow_hashref(); print "There are ".$counts->{'a'}." in this table";