Tiger moth caterpillars have been seen medicating themselves to treat a nasty influx of parasites.
The caterpillars develop a fondness for certain plants to fight a parasite infection
Scientists found the caterpillars' sense of taste actually changed when they became infected with parasites.
Instead of avoiding certain alkaloid plants, the caterpillars actually developed a fondness for them.
This change in diet helps to beat the creatures' parasite infection, the researchers report in Nature.
The finding is slightly unusual because often when animals change their behaviour following a parasitic infection, it is to the invaders' benefit.
"It is a new and surprising kind of interaction between organisms," said Elizabeth Bernays, of the University of Arizona, US.
"When parasites change the behaviour of their hosts, it's usually to their own advantage."
Race to live
Caterpillars of the tiger moths Grammia geneura and Estigmene acrea , which live in the grasslands of southern Arizona, US, are susceptible to a range of insect parasites.
The parasitic flies lay eggs on the surface of the caterpillars' skin which, on hatching, bore into the larvae's flesh.
It is here that the struggle for life between host and parasite really begins.
The parasite's objective is to feast on the generous supply of live tissue, before it pupates and bursts out of the dead caterpillar.
If the caterpillar is to survive such an onslaught, it must develop an effective defence strategy.
Instead of eating a wide range of plants, which the tiger moth larva usually does, the caterpillar becomes much more specific: it homes in on plants that are particularly toxic to its parasites.
These plants, such as woolly plantain, produce chemicals known as pyrrolizidine alkaloids and iridoid glycosides.
Not only do these chemicals wash through the caterpillar's body, making it an unattractive meal, they also collect in its skin, deterring future invaders.
Dr Bernays and her colleagues found that, when a caterpillar acquires a parasite infection, its taste cells react differently to the chemicals in food.
These cells become more responsive to the protective chemicals and less sensitive to other chemicals, which are usually distasteful to the caterpillars.
Just how this change occurs in the caterpillars is not known yet.
"It's still a mystery how they do it," Dr Bernays said. "But the result for the caterpillars is the same: they can survive because they find the protective plants more tasty."