my $delete_tmp = find(sub {unlink($_) if -f and /\.tmp$/i}); ... $delete_tmp->($one_directory); ... $delete_tmp->($other_directory); ..