I had a 36 gallon filled with shrimp and experienced a similar situation.
I would recommend you to see how bad the problem is. If you are seeing wayyyyyyyyy too many of these little worms. maybe actually replanting your tank is a good idea. Since they reproduce extremely fast, you may as well just redo your tank.
I went on google and found some planaria killer pills from some Japanese store, not too sure if they still have it but they do an amazing job in kill them. To my tank, I re did the whole thing, new substrate, rocks and washed my old plants. When the shrimp was stored in a temp housing, I sort of picked out the "dead" ones before putting them back into the tank again.
it is a pain in the butt to do all of that but it does help clean up the tank very nicely. Make sure the substrate, rocks, and plants are all clean when you do it. Overfeeding also caused my tank to have these little killer.
Hope it helps!