I'm not talking about compiling perl into machine code. I'm talking about spotting some common patterns and replacing them with optimized versions that do the same thing. Still with perl OPs.
Perl already does this. Subroutines with empty prototype and constant return value are inlined (not actually called on the runtime). If statements that have constant false condition will not be included in the internal compiled structure at all. Currently existing optimizations are pretty straightforward, I think mostly constant folding, to avoid long startup time of a program. What I mean is to have more of those with less focus on fast compile time, as an executable flag for easy on/off. Yes, potential gains may not be worth it or there might be some technical reasons why this isn't viable.