for my $i (0 .. $#records) { # check here sleep (10) if $i == 11; $records[$i]->{line} = $i + 1; # print HERE not outside the loop }