This is due to the way proc behaves with the keywords of the control flow: return , raise , break , redo , retry , etc.
These keywords will skip from the area where proc defined, otherwise lambda has its own scope so that these keywords go from lambda's .
In your second example, proc is defined in the scope of main. And as the tadman comment below, you cannot return from main , only exit .
Your code will work if you switch from proc to lambda .
megas source share