The wall, which has sections up to three meters high and secured with barbed wire, separates people living in precarious housing on dirt roads with no basic services from residents of an asphalt-paved gated neighborhood of well-to-do homes, some luxurious mansions even equipped with swimming pools.

The wall, which has become a symbol of deep inequality in the Andean nation, began to be demolished thanks to a ruling by the country's constitutional court, following a four-year legal battle.

"It affects free transit, but also hurts the dignity of the neighbors," said court magistrate Gustavo Gutierrez, who is overseeing the demolition. "It is a division that separates two social groups that should not exist."

Residents of the wealthy La Molina district began building the wall in the 1980s, citing security concerns during years of violence from the Shining Path, a Maoist rebel group which intended to overthrow the government.

Their campaign of guerilla warfare led to 20 years of brutal conflict with Peru's armed forces, leaving some 69,000 dead or missing, according to official figures. The group was largely destroyed in the 1990s, but the wall dividing La Molina and the poorer Villa Maria del Triunfo remained and has grown in size.

Francisco Dumler, the municipal manager of the La Molina, said residents would comply with the ruling but the demolition could take time due to unforeseen costs.

"It must also be made clear that there is no possibility of building paths or any kind of vehicle access to allow crossings directly into La Molina from Villa Maria del Triunfo," he said.

Other residents said they were worried about people from outside moving onto the land. La Molina boasts lush parks and large residences that can cost several millions of dollars.

On the other side of the wall, humble houses are being built increasingly high up the hill, where residents use sticks or run up to navigate the steep inclines.

(Reporting by Anthony Marina, Carlos Valdez and Marco Aquino; Writing by Sarah Morland, Editing by Nick Zieminski)