I asked myself that same question years ago when I first started learning about Worms and how they were beneficial to all plant life especially the ones in our own gardens.
If you were just like me, before I started worm farming, then you would think that they just eat the dirt that they wiggle around in. Well, this is true only to some degree.
You see, there is only one group of worm that eats soil and decaying matter and that is the endogeic group. Like the Alabama Jumper (Species Pheretima Hawayanus,excellent garden worms) builds lateral burrows and rarely comes to the surface. They are pale, or have a pale pinkish tone. these are the only type of worms that eat soil and decaying matter. these can be good worms to have in your garden since they have lateral burrows which help to aerate the soil. these are your medium sized worms
Other species will stay at the top and feed on rich decaying matter like the red wiggler. The night crawlers, like the famous Canadian night crawler, will come up to the surface and grab its lunch and take it back down into its deep vertical burrow which can be sometimes up to 6ft. deep.
so what is this rich decaying matter I'm talking about?...Dead plant life.
A worm will eat just about any plant that is dead. But it doesn't really eat the plant itself. It can't. It has no teeth. Much like a chicken it has a gizzard that helps grind its food. It depends greatly on bacteria, fungi, nematodes, and protozoa to break down the food so it can slurp up the the tiny organisms that broke down the plant in the first place. Kind of like you and I would drink one of our favorite ice cream shakes.
So I hope that helps you Aqila. If you want a better understanding of what foods they eat and how to feed them, then go over to the worm food section of this website.