Sounds like tapeworm! It comes out in segments that can keep moving like individual worms. They look like rice when dry. Max had one once.
Save a stool sample to take to your vet ASAP.
Here is the thread about Max:
http://www.yorkietalk.com/forums/yor...tapeworms.html