These are tapeworms. It requires either droncit or drontal to safely and effectively get rid of them. It is a one time pill that in severe cases can be given once again in 3 weeks if needed. It is prescription only but with a stool sample dropped off showing the worms, most vets who have seen your dog before will gladly give you the pill. It is inexpensive but a great medication.
Tapeworms come from ingesting fleas, so it's likely your dog has also had a flea or fleas on him. You'll want to start him on advantage or frontline at least 2 consecutive months to kill any fleas at all stages of their life cycle.
Best of luck, and let me know if I can help further.