You get the body you're born with. You can stretch, eat the right foods, only do the right strength and conditioning in the gym, but if you're are suspect to hamstring tears, then it's gonna happen regardless. Players like Salah, Messi etc absolutely take care of themselves, but others do to. Salah and some others are just blessed with very well balanced body types, naturally.
I don't think I'd ever sign a player that has had 2 or more hamstring issues. They'll always have them.