SALEM – A Lynn man who admitted dealing cocaine three times near a school in Swampscott and Lynn will serve up to five years in prison before being placed on probation for another two years.In Salem Superior Court Wednesday afternoon, Nelson Perez, 62, whose last known address was 10 Estes St., Lynn, changed his plea of innocent to guilty to three cases before Judge Howard J. Whitehead.Perez will serve three-to-five years in prison for trafficking cocaine before being placed on probation for another two years for dealing cocaine.The judge also sentenced him to two and one-half to three years on the school violation charge, but that punishment will run simultaneously with the primary term of incarceration, instead of one after the other.The judge sentenced him in accordance with an agreement reached between Assistant District Attorney Kristen R. Buxton and defense lawyer Lawrence J. McGuire.The first case Perez pleaded guilty to involved charges of possession of cocaine with the intent to distribute and possession of cocaine with the intent to distribute cocaine within a school zone. It concerned his arrest in Swampscott on Aug. 11, 2005 when he was stopped on Humphrey Street for driving on a suspended license and found he had an active warrant for his arrest.Police confiscated three bags of cocaine from his pants pocket, additional cocaine in his vehicle along with $415 in cash, within yards of the Swampscott Middle School.Then he pleaded guilty to a reduced charge of trafficking over 14 grams of cocaine in connection with his arrest on Oct. 7, 2005 in Lynn when he was stopped in his car and police seized over 23 grams of cocaine from a bag at his feet. A search of his residence, then at 19 High St., in Lynn, revealed additional cocaine along with drug related items and $281 in cash, believed to be proceeds from drug sales.His confession to the reduced charge spared him of a minimum mandatory five-year prison term on the charge.Then he was arrested in Lynn on Aug. 23, 2007 for dealing a quantity of cocaine to an undercover officer during a hand-to-hand drug sale.The judge credited Perez the 147 days he has been in custody awaiting trial on the cases.