There are several types of worms you might find in your garden. Earthworms are the most common, but they are not harmful. In fact, they actually enrich the soil. Another type of worm, called the grub worm, is not so beneficial. The grub worm is well-known for leaving dead patches in gardens where it has eaten all of a plant's roots. If you find that you have grub worms in your garden, you will need to get rid of them.
Purchase a packet of nematodes from your local garden center. Nematodes can safely be applied to your garden. They are tiny parasitic worms that will attach themselves to your grub worms and eat them from the inside out. This is an effective and natural way of dealing with the worms.
Spread milky spore disease around your garden. The grub worms will eat the disease and then become sick and die. It is safe to use around your pets and children, and will only harm the grubs.
Spray neem oil over your garden. It will kill any insects that it comes in contact with, including worms. The benefit to using neem oil is that it is all natural. You will need to mix 2 Tbsp. of neem oil with 1 gallon of water. Place this mixture in a sprayer and spray where you have the worms.
Apply a chemical insecticide to your garden in the later part of July. Make sure the insecticide contains the active ingredient imidacloprid, or halofenozide. If you apply it in the spring, it will not be as effective. Follow all of the instructions on the product label for your own safety.