Don gloves, jeans and long sleeves for this process. Don't leave any skin exposed. Wear safety goggles as well. If you have long hair, tie it back.
Prune the branches off the pencil cactus and dispose of them. Don't leave any cuttings lying around because this plant propagates from cuttings and will re-sprout. Cut the cactus until you have only 2 to 3 feet of trunk left.
Dig into the soil 2 feet from the base of the cactus and find the root system. Dig inward and downward to isolate the roots from the soil, then push the nose of the shovel under the root system and lift up. Dispose of the roots as you have the foliage, then fill the hole back in.