in reply to Question about curious performance of if...elsif block
One trick that might help here is to define an array (or a hash...) of subs; that is to say, of “code references.” Directly fetch and execute (if it exists) the specific subroutine that you want to execute. So you’re not performing 39 if-tests in a row in order to determine that you want to execute subroutine #40...
I am not asserting that it will help in your particular, very rarified and performance-hungry case. Only empirical testing would establish that.