my $sql = "SELECT * FROM $course WHERE column = ?"; my $sth = $dbh->prepare($sql); $sth->execute($userid); if (@row = $sth->fetchrow_array) { # row was found where column == $userid } else { # no such row found }