for my $file (@files) { # Perl will exit the loop when the array has been processed } #### use File::Path 'remove_tree'; for my $file (@files) { unlink($file) if -f $file; remove_tree($file) if -d $file; }