my %keepers = map {$_=>1} @KEEP ; # OR declare %KEEP instead of @KEEP rmtree ([grep {not $keepers{$_} }@files]);