This perlmonks node explains how to implement mindepth and maxdepth from GNU's find.
Basically, they count the number of slashes in a directory, and use that to determine the depth. The preprocess function will then only return the values where the depth is smaller than the max_depth.
my ($min_depth, $max_depth) = (2,3);
find( {
preprocess => \&preprocess,
wanted => \&wanted,
}, @dirs);
sub preprocess {
my $depth = $File::Find::dir =~ tr[/][];
return @_ if $depth < $max_depth;
return grep { not -d } @_ if $depth == $max_depth;
return;
}
sub wanted {
my $depth = $File::Find::dir =~ tr[/][];
return if $depth < $min_depth;
print;
}
Tailored to your case:
use File::Find;
my $max_depth = 2;
find( {
preprocess => \&preprocess,
wanted => \&wanted,
}, '.');
sub preprocess {
my $depth = $File::Find::dir =~ tr[/][];
return @_ if $depth < $max_depth;
return grep { not -d } @_ if $depth == $max_depth;
return;
}
sub wanted {
print $_ . "\n" if -f; #Only files
}