in reply to Re: getting files from Dir
in thread getting files from Dir

Why don't you check your match for success? If if fails, you get the $1 from the previous iteration. That's probably not what you intended. Also, I'd use \d+ instead of \d* since we're not interested in matching tim without any following digits. It probably should be anchored to the front of the string too, by the OP's spec.
my @wanted; opendir my $dh, $dir or die "Failed opening $dir: $!"; foreach (readdir $dh) { next unless /^tim(\d+)/; my $num = $1; push @wanted, $_ if $num > 14 and $num < 51; } closedir $dh;
Personally, I'd wrap the whole thing in a do block and use grep, so that I don't need to track my handles explicitly:
my @tim_file = do { opendir my $dh, $dir or die "Failed opening $dir: $!"; grep { my ($num) = /^tim(\d+)/; defined $num and $num > 14 and $num < 51; } readdir $dh; };
Note that when you assign a match's captures to a list, failed expressions will return undef, so here I can implicitly test for success by testing the definedness of $num.

Makeshifts last the longest.