my $dir = '/xml'; my @all_files; opendir(DIR, $dir) or die $!; while (my $file = readdir(DIR)) { next if ($file =~ m/^\./); next unless ($file =~ m/\.xml$/); push @all_files, $file; } closedir(DIRHANDLE); #Get the range using a slice here, can be values coming from the dropdown menu"; my $from = "0"; my $to = "1"; my @new_all_files = @all_files[$from,$to]; my $open_this; for my $x_file (@new_all_files){ ...stuff }