You should take your dog to the vet for regular checkups to get them tested for worms.
If they have worms then the vet can prescribe worm medicine for your dog which will kill existing worms and prevent further worms from developing in your dogs.
If worms in your dog are left untreated the worms can eventually kill the dog so it's important to get the dog treated for worms.
There's also some cheaper over the counter worm medicine that doesn't require a vet prescription so if you can't afford a vet you can try the over the counter worm medicine but if you can it's best to get the vet prescribed worm medicines because it works much better.