Although this pest looks like a worm or a slug, it's neither, and that makes a difference in what control measures work on it.
Upload your photo here.
Identifying the Pest
Some larvae look like caterpillars with three pairs of large legs and seven pairs of smaller false legs. The larvae may appear individually, but often form clusters of dozens of chewing defoliators. It's common to see them lined up along the edge of leaves or needles. When disturbed, they may raise their abdomen and tail end into an s-shape defensive position.
Other sawfly larvae resemble slugs, with a slimy non-segmented body. This group of sawfly larvae usually feeds only on the leaf surface, leaving a skeleton of leaf veins where they feed.
Sawfly Life Cycle
Adult sawflies lay eggs in or on leaves. The larvae hatch out in late spring or early summer and begin feeding. They spin cocoons when fully grown. Some species have only one generation per year; others may have several generations.
The best time to control sawflies is early in their larval stage. The natural insecticide spinosad will control sawfly larvae. Conventional insecticides such as malathion are also effective. Bt (Bacillus thuringiensis), which is an effective natural control for true caterpillars, is ineffective on sawfly larvae.
Most sawflies attack only one species or closely related species of plants, and the common name of the sawfly usually includes its host. Examples are:
Ash Sawfly (Blackheaded and Brownheaded)
Dusky Birch Sawfly
Loblolly Pine Sawfly
Mountain Ash Sawfly
Pear Sawfly (also known as Pear Slug)
Pine Sawfly (European, Introduced, Redheaded, and Virginia)
White Pine Sawfly
Yellowheaded Spruce Sawfly