use strict; use warnings; use Modern::Perl; for ( 1 .. 10 ) { my $iterator = $_; test(); sub test { say $iterator; } }