ETA: This is valid in perlfaq5: How to delete a directory tree?
Use File::Path , the main module.
perl -MFile::Path=remove_tree -we 'remove_tree("Sample",{keep_root=>1}) or die $!'
The keep_root parameter keep_root remove_tree to save the top directory:
keep_root => $ bool
If set to true, all files and subdirectories will be deleted, except for the originally specified directories. This happens conveniently when cleaning the directory from scratch of the application.
source share