Police say 31-year-old Ray Sanchez, of Coram, exposed himself to an 8-year-old girl inside a Target store in Medford on October 10.
The mother took pictures of Sanchez before he fled the store, according to authorities.
He is also accused of public lewdness in front of an elementary school in East Setauket on October 15.
In that incident, police say two 13-year-old girls observed Sanchez masturbating in a vehicle parked in front of the school.
Sanchez was arrested on charges of endangering the welfare of a child, exposure of a person and public lewdness.