use strict; use warnings; use 5.010; for my $num (1 .. 5) { say "start of for loop: $num"; {say "in block: $num"}; sub test { say "in function: $num"; } test() } --output:-- start of for loop: 1 in block: 1 Use of uninitialized value $num in concatenation (.) or string at 3perl.pl line 11. in function: start of for loop: 2 in block: 2 Use of uninitialized value $num in concatenation (.) or string at 3perl.pl line 11. in function: .. ..