... my $sql = 'select count(*) from replies where reply_id=?'; my $sth = $dbh->prepare($sql) or die $dbh->errstr; ... my $rc = $sth->execute($q->param('id')) or die $sth->errstr; my ($count) = $sth->fetchrow_array if ($rc == 1); ...