do you just want it to list all files, or to return them in an array. If merely printing them is enough, you do something like:
sub print_txt_recurse() {
my ($filepath, $level) = @_;
#some code to get file paths and and print txt files going through each file
elsif (-d $file && $level > 1 ) {
print_txt_recurse($file, $level - 1);
}
return;
}