use File::Path; rmdir $_ for reverse mkpath [ join( "/", ("foo") x 1000 ) ], 0, 0755;