#!/usr/bin/perl use warnings; use strict; use File::Find; use File::Path qw(make_path remove_tree); my $path="/opt/ssi/www/shop_templates/cache"; find(\&audit, $path); sub audit { # your logic for which paths you want to keep/toss. # in here, the following apply: # $File::Find::dir = /opt/ssi/www/shop_templates/cache # $_ = foo.ext # $File::Find::name = /opt/ssi/www/shop_templates/cache/foo.ext ... }