#!perl use strict; use warnings; use File::Find; my @ext = qw(.tmp .bak .$$$ .chk .old .gid .fts .ftg .log .dmp .--- .prv .temp); # build and compile an RE that uses alternation operator | my $re = join '|', map{ quotemeta } @ext; # compile RE. ?: avoids capture into $1 from ( ) # and the $ locks the matched ext to end of filename $re = qr/(?:$re)$/; sub wanted { return unless -f $_; return unless m/$re/; warn "Unlinking $File::Find::name\n"; unlink $_ or warn "\tUnlink $_ failed $!\n"; } find(\&wanted, '/');