Hamstring (?) Issues

I have a recurrent back-of-leg problem that I get from running long races. Training is usually no problem, or less of a problem, but when I ramp up speed and distance at the same time, I have issues. During the race (most recently a marathon 3 weeks ago) I began to feel tightness in the hammys up close to my butt, about halfway. It didn’t get much worse, or that painful for the rest of the race. However, after the race, that area was incredibly tight and a little painful. I had trouble touching my toes, whereas before, I’m nearly able to palm the ground (quite flexible). And now, doing as little as 5k at slow pace, is enough to aggravate the injury. I think I’m a pretty flexible guy - what am I doing wrong?

If this were a one-time thing, I’d chalk it up to not being well-enough prepared for this particular race. However, this is a recurring problem. Usually races 15k and up will do it to me. It does go away with rest and/or reduced training, but usually takes a month or so to subside. I’m getting tired of dealing with this, though. Any suggestions at alleviating the problem would be appreciated.

cheers