Every caterpillar of the current 170,000 different species of Lepidoptera has their own special food for that species. This because over 100 million years ago, when Lepidoptera evolved from their precursor insects, some fed on primitive plants. This was not good for the plants that they ate. So over the millennia, plants evolved to create internal poisons to kill any caterpillars feeding on them. Different plants evolved different metabolisms, and split into different families and different species, each making different poisons.
Meanwhile the caterpillars evolved into different families and species: some gave up eating plants and adapted to eating animal hair (like clothes moths), or animal dung, or seeds, or Lichen, or other insects. Also many caterpillar species evolved to be able to metabolise the poisons without harm in the various plant families that were evolving.
And this escalating war between caterpillars and plants, of defence and counter-defence, has been going on continually over the last 100 million years or so, and this has led to there now being the 400,000 species of flowering plants, and the 170,00 species of Lepidoptera, that we have in our world today, with each plant having only a limited number of Lepidoptera that can feed on it, and each caterpillar only being able to feed on only those plants or other things that it has adapted to feed on.
(written 13 March 2020)