Or rather, a goal begets a strategy, and a strategy begets sub-goals. Beautifully at some point these sub-goals start being optimized for. A few steps of this is how I believe humans went from the sub goal "Survive, eat, reproduce" to "Make art, understand life, explore the world".
The cool thing is that I think this extends beyond humans to tools. Because at some point humans had a sub-goal of "hit thing hard" they made a hammer. And this hammer has a goal (or a purpose) which is "hit things hard". This purpose can be traced back, through human sub-goals, to the final goal of evolution: "reproduce".
Note that I am not saying that the point of a hammer is to produce more hammer. But the point of a hammer is (very indirectly) to allow a human to reproduce.
Interestingly there is a weird game of telephone that can happen, where the sub-goals are imperfect for achieving the final goal. I would argue that this is (part of) why humans can be truly selfless. Take a soldier going to a battle he considers unwinnable but going out of a sense of duty / fear of ridicule. This will not help him reproduce, since the battle is unwinnable it will not help his progeny reproduce either. From the 'ultimate' goal, this is an irrational step. But there are sub-goals at play. Things like "be honorable", "do your duty".
This idea that a sub-goal can subvert the 'ultimate' goal is very beautiful to me. It means that evolution is not some tyranny that sets our purpose in life. Instead evolution brought 'purpose' into the world. And then some stochastic process put you and me on into the universe with some, vaguely related, sense of purpose. But we have our own purpose. Sure our purpose was 'created by' the ultimate purpose of evolution. But our purpose is not subordinate to the ultimate purpose of evolution. A human life can have so much more value that just "continue the genetic line and have children". I find that freeing.