my $sqlcount = 'SELECT COUNT(*) FROM grp_def WHERE grp_name = ?'; my $sth = $dbh->prepare($sqlcount) or die "Cannot prepare: " . $dbh->errstr(); $sth->execute($grp_name) or die "Cannot execute: " . $sth->errstr(); my $occurences = $sth->fetchrow_arrayref->[0]; print "result: $occurences\n";