A "preliminary hearing", of the kind depicted in the Perry Mason novels, is a procedure in California and some other states. It is an alternative to a Grand jury proceeding. It is used to determine whether there is probable cause to put the defendant on trial.
Such hearing are mostly rather routine, and rarely reach the level of drama shown in "Perry Mason". But the prosecutor does present witnesses, which the defendant's lawyer can cross-examine. The defendant may, but rarely does, also present witnesses.
Note that Mason stories sometimes involved a full trial, not just a preliminary hearing.
Gardner, who wrote Perry Mason, was a practicing attorney in CA, and most of the law as he shows it was accurate when he wrote, but he often showed legally possible but highly unlikely events to improve the drama of his stories.