From http://search.cpan.org/perldoc/Path::Iterator::Rule#SYNOPSIS, you add whatever checks you need, same algorithm as File::Random, it reads the whole directory tree but only one filename at a time in memory
sub random_file {
my @dirs = @_;
my $rule = Path::Iterator::Rule->new; # match anything
$rule->file->size(">10k"); # add/chain rules
# iterator interface
my $next = $rule->iter( @dirs );
my $random_file;
my $i = 0;
while ( my $file = $next->() ) {
if( rand $i++ < 1 ){
$random_file = $file;
}
}
return $random_file;
}