my $music_path = ".\\music"; # probably should make this an absolute path... open my $fh, "D:\\tree /f /a $music_path |" or die "cannot run tree on $music_path: $!"; while ( <$fh> ) { # everything else stays the same... }