my $path = "."; get_list($path); sub get_list { my $path = shift; opendir(my $dh, $path) or die "Cannot open dir $path: $!\n"; while (my $f = readdir($dh)) { next if $f =~ m/^\.{1,2}$/; if (-d "$path/$f") { get_list("$path/$f"); } else { print "$path/$f\n"; } } closedir($dh); } Implemented: my $path = $mainconfig->val( 'Icinga','configpath' )."/twill/walkthrough"; my $hostlist=get_list($path, []); sub get_list { my ($path, $hostlist) = @_; opendir(my $dh, $path) or die "Cannot open dir $path: $!\n"; while (my $f = readdir($dh)){ next if $f =~ m/^\.{1,2}$/; next if $f =~ m/^\.svn$/; if (-d "$path/$f"){ get_list("$path/$f", $hostlist); }else{ push @$hostlist, "$path/$f"; } } closedir($dh); return $hostlist; } print Dumper $hostlist; exit;