in reply to How to no goto or gosub

Others have suggested working code you could use. I am offering an explanation.

In Perl, calling a subroutine is not like gosub label. What you wrote as sub ENDING_BRACE; is, in Perl, what's called a "forward declaration". It does not define the subroutine, it merely tells the Perl compiler that you intend to define a subroutine named "ENDING_BRACE". Your code has no definition for ENDING_BRACE.

A possible definition might be:

sub ENDING_BRACE { # handle ending brace }

But, in your code as written, If $gas_cost were less than 1, the code "handle ending brace" would be executed, then ENDING_BRACE would return control to where it was called, so then "stuff here" would be executed, which is not what you want.