my @found_array = do { local @found; find \&wanted, $dir; @found }; sub wanted { no strict 'vars'; push @found, $_ # if . . . }