At compile time, the code within {} is compiled into a prototype anonymous sub (CV), which is squirrelled away somewhere.
At run time, the action of sub {...} is to make a copy of that sub (allocating a new CV), and then return a reference to that new CV.

As an optimisation, if the sub isn't a closure, then rather than copying the CV, a reference is just returned to the original prototype CV. This optimisation isn't perfect; in particular if one blesses $f, then the prototype CV gets blessed, and any new executions of that $f = sub {...} assignment get a blessed coderef.

Finally, note that perl maintains a pool of spare CVs; when one is freed, it gets returned to the pool and that may get reused soon.

Of course, these are implementation details which are subject to change.