for my $i (2..12) { for my $k (5..18) { open my $handle, "<", "path" or die; # my means that the $handle here is a new one on each call. ... # closed is called automatically here } }