use autodie; for my $dir (qw/d1 d2 d3 d4 d5/) { open my $LIST, '<', "$dir/list.txt"; # read from $LIST and do something with it close $LIST; }