Caterpillars, they're a bit soft, aren’t they? Unappreciated ugly creatures, waiting for their metamorphosis.

All they do is slowly crawl around, munching on plants until they literally spread their wings and fly away.

Not so for all it turns out.

While the majority eat only plants, a certain group has evolved curious, clever ways to eat other unwitting insects.

They mostly feed on soft bodied, sap sucking insects such as aphids (plant lice), ant pupae and larvae. These victims are often duped into a false sense of security by these caterpillars' sneaky tactics.

Some even embed themselves within ant nests and are fed regurgitated food from ants themselves, like cuckoos in a nest.

These "wolves in sheeps' clothing" use a chemical camouflage to mimic the ants' smell which deceives them into thinking they are one of their own.

Others embed themselves within a group of tasty aphids that the ants herd for honeydew, but go undetected as once again they copy the smell of their aphid prey.

"I refer to this as a cloak of invisibility," said David Lohman of City University of New York, US. "They eat aphids but the aphids' own protective ants don’t attack them." 

Masters of sneak

This group, the Miletinae, are a subfamily of the second largest group of butterflies, Lycaenidae, and are found on four continents.

And they are extremely rare, the 140 species represent less than 1% of the 175,000 or so different species of Lepidoptera, the group that includes butterflies and moths.

They are so rare that a new study looking at the evolutionary history of this particular group took 20 years to collect enough samples to study their family tree.

They have really cracked the code for ant communication

The authors behind the research, published in the journal Evolution, wanted to understand the effect their unusual, predatory lifestyle had on their evolution. 

Shifting from a plant-based diet to eating insects itself is not that rare, but those species who make the change usually do not survive for long, explained Dr Lohman, who is one of the lead authors of the study.

This small group has therefore long puzzled researchers: how did they manage to survive this lifestyle whereas other had not?

The answer, it is now apparent, lies with ants.

The Lycaenidae family's historical relationship with ants has been key to helping the Militinae occupy their dietary niche, said another co-author of the study, Naomi Pierce of Harvard University in the US

Whereas the former can be beneficial to the ants, sometimes even making them a nourishing sugary substance, the latter are parasites.

Ant ghosts

"They have really cracked the code for ant communication. They secrete chemicals on the surface of the larvae that appeases the ants so the ants don’t attack the caterpillars," said Prof Pierce.

The reason Militinae were able to evolve and persist in this carnivorous niche is therefore precisely because they have this pre-adaptation of living and co-operating with ants, she added.

But not just any ant will do, the researchers discovered. Just as plant-eating caterpillars only eat certain species of plant, carnivorous caterpillars eat particular groups of ants.

"The close relatives of one lineage will associate with certain closely related ant species. We call this the ghost of ant association past as there's no relation between these caterpillars and ants other than they are feeding on insects tended by a particular group of ants," Prof Pierce told BBC Earth. 

This association therefore ensures the caterpillars will always find their prey.

Lohman said it was possible that butterflies could even be sniffing out ants their future caterpillars could exploit to survive.

During his field work in Asia he noticed that a group, whose caterpillars feed on aphids, would circle ants even when there were no aphids present.

"It makes sense that this habit of living with ants has been passed on from one generation to the next. It has predisposed them to finding ants and along with the ants they often find the insects that they eat," Dr Lohman said.

This parasitic relationship is nothing new. When reconstructing the Miletinae's family tree, the team found that their family was up to 60 million years old, a time when forests thrived and covered much of Earth.

Their rare dietary habits persist when they become butterflies.

Unlike most which drink nectar, adults of this carnivorous group drink the honeydew secretions of aphids and other sap-sucking insects, the same ones their larvae offspring will later eat.

Follow Melissa Hogenboom and BBC Earth on twitter.