A Brooklyn man was charged after an undercover operation in which he tried to sell an undercover detective hundreds of bags of heroin, police said Sunday.

Officers from the Nassau-Suffolk Heroin Task Force, after an investigation, arranged a meeting with Jason Perez, 30, of Park Avenue, Brooklyn, to purchase the drug from him, a police news release said.

Perez was arrested after he met the undercover detective at a prearranged location in Wantagh and tried to sell him the heroin, police said.

Police said Perez had 390 bags of the drug with him.

The defendant is charged with criminal sale of a controlled substance in the third degree and criminal possession of a controlled substance in the third degree, police said.

At arraignment Sunday in First District Court in Hempstead, Perez was ordered held on bail set at $50,000 cash or bond.