my ($rand,%seen,@files); my $number=shift || 15; { $rand = substr(rand,-7,4); unless ($seen{$rand}++) { ## Files must be unique! push @files, "elmo$rand.txt"; --$number or last; } redo; } #### my @files = ; ## Convert the list to numbers and warn about any unusual elmos: @files = map { m/^elmo(\d{4})\.txt$/ and $1 or die "What is $_ doing here?!\n"; } @files; ## Now figure out where the largest gap is: my ($diff,$old,$high); for (sort @files) { $diff=$_-$old and $high=$_ if $_-$old>$diff; $old=$_; } ## Now go in order, starting at the first value after the gap: for ( map {$_->[0]} sort {$a->[1] <=> $b->[1] } map {[$_, $_ >= $high ? $_-10000 : $_]} @files) { print "Parsing elmo$_.txt\n"; }