Do you need to be flexible to do yoga?
Sure, but only in your mind.
Those fancy 'poses' you see are called Asanas. I took a class with a delightful instructor who called them shapes.
To do yoga you need to drop the ego and accept where you're at. If you're pushing to create a 'pose' or driven by how you feel something should look you've got the wrong approach.
So anyway, back to the question. Asanas are just one of seven other parts of yoga. It just happens to be the most photogenic so it's more visible.
While it might look like you need to touch your toes in yoga...
The bigger challenge is being flexible in your mind to accept that it may never happen even with practice. But that doesn't mean you can't enjoy the practice and work towards it. Besides what does touching the toes actually mean? Just that, you can touch your toes. Nothing more significant. There are so many more benefits to yoga than just flexibility. There's strength, balance, mindfulness, and with regular practice you become more in tune with your body.