At least on my 5.28, the difference is negligible:
use warnings;
use strict;
use Benchmark 'cmpthese';
cmpthese(-2, {
predecl => sub {
my $y;
my $x;
for $x (1,2,3) { $y+=$x }
},
lexical => sub {
my $y;
for my $x (1,2,3) { $y+=$x }
},
});
__END__
Rate predecl lexical
predecl 9175035/s -- -1%
lexical 9275893/s 1% --
But wakes in me primordial fears
Yes, I know the feeling well. But my philosophy has become: first, code so that it works, avoiding only the really obvious performance mistakes (like scanning an array instead of using a hash and the like). Then, if it's fast enough for your puproses, you're done. But if you want to optimize, remember that optimization is a science: measure the performance, identify the hotspots, benchmark the alternatives, modify the code accordingly, measure the difference in performance, and repeat until the performance becomes good enough for your purposes.