sub perlish { chomp; $_ = realpath($_); # follows links, makes full path ( -d ) ? ( $processed{$_} ? () : do { my $basedir = $_; $processed{$_} = 1; # prevent infinite recursion into links # turn results of ls into relative paths before recursion # and avoids using chdir map &perlish, ( map {"$basedir/$_"} `ls $_` ); } ) : $_; } %processed = ( getcwd() => 1 ); print join "\n", (map &perlish, `ls`),"\n";