$sqlCount = "SELECT COUNT(*) FROM $user_data_db_name WHERE USER_NAME=?"; $sth = $dbh->prepare($sqlCount) || die "Cannot prepare: " . $dbh->errstr(); $sth->execute($form_values{'USER_NAME'}) or die "Cannot execute: " . $sth->errstr(); my $occurences = $sth->fetchrow_arrayref->[0];