Planaria worms eat decaying matter/waste also algae and eggs of egg laying fish inverts too snails, shrimp, crayfish ect. They are prone to nesting in filter systems steady supply of waste/food. I had them before found no meds to treat them, but started over from scratch start boiling everything out.
Not boiling hot water, but hot enough to burn your hand hot. I mean will instantly DOA any worm. That's a last resort though if nothing else works. Their's meds out there that will say it will kill them but don't work. Just money out of your pocket.
You can downsize the population by water changes, but most likely another boom within a few months could happen. Some people like them others don't enemies to anybody breeding fish that lay eggs. The ones on the glass come out when they are hungry eating algae off the glass. If you see hundreds chances are there are prob thousands that you don't see.
GL with the worms bud hope it helps.