debug "this..." if LVL1; ... debug "that .." if LVL3; #### sub debug { print "$_\n" for @_; } #### BEGIN { ... read the levels that should be ON to %debug for (1.. $count_of_levels) { eval "sub LVL$_ () {$debug{$_}};"; } }