ALFRED — With vengeance on his mind, David Glenn Hobson escaped from a New Hampshire jail by scaling a razor wire fence before heading to Maine, where he eluded search teams for days by hiding in the woods and eliciting help from family and friends, officials said Wednesday.

Hobson was arrested Tuesday evening outside a store in Rochester, N.H., where his ex-girlfriend was employed but not working at the time.

Police believe revenge against his former girlfriend and her boyfriend drove him to escape from jail, send her a threatening text message and remain on the lam for five days as dozens of law enforcement officers searched for him with dogs, aircraft and even thermal-imaging equipment. Hobson apparently was angry that his ex-girlfriend had broken up with him and taken up with somebody else, officials said.

Given what they knew, police considered Hobson dangerous and resolute.

Hobson, 34, didn’t say anything during a brief appearance Wednesday in Ossipee District Court, where he was charged with escape. Bail was set at $500,000.

Hobson was awaiting trial on burglary charges in the Carroll County House of Corrections in Ossipee, N.H., when he escaped Dec. 1 by scaling a fence, climbing over razor wire and jumping off a 12-foot-high building.

A tip led police to a Walmart in Alfred where Hobson was arrested while getting into a car driven by another person. He had $3,000 in cash and illegal drugs on him, said David Cargill, New Hampshire’s U.S. marshal.

Cargill declined to say who was picking up Hobson but said police think Hobson was ready to leave the area.

“We think he was looking to get away, looking for another car and going to head out somewhere else,” he said.

Hobson had cuts and bruises when he was arrested. After he first escaped, officials surmised that he was seriously hurt by the razor wire.

Officials still have questions about where Hobson got the cellphone and cash, how he got around and who else helped him. Additional charges could be filed, authorities said.

When asked how cooperative Hobson’s relatives had been with police, Nyitray hesitated before saying, “I think they cooperated as much as they felt they needed to ? and no more.” Hobson’s family declined to speak to reporters.

The only other inmate to escape from the 8-year-old Carroll County House of Corrections walked away from a farm crew in 2009, and he was quickly apprehended, Sorensen said.

When asked if the commission had discussed any improvements to the jail, Sorensen said that the board had considered adding more officers and that two were already in the proposed budget. The jail has 29 corrections officers and 56 inmates, with space for as