Although yoga might teach you how to touch your toes, the important lesson isn’t in the touching. It’s in the journey getting there. Self acceptance, nonjudgment, breath, mindfulness. That’s the difference between yoga and just touching your toes.
But to answer your direct question, there are a lot of other ways to increase flexibility in the hamstrings without going that far, and without rounding your back (both of which can hurt). Consider googling “yoga poses for hamstring flexibility”