Here is a script that shows exporting results from a subprocess to a parent shell using a temporary file:
#!/usr/bin/env bash
process_line() {
if [[ $* == *foo* ]]; then
echo "found_foo=1" >>$IPC
fi
}
IPC=$(mktemp)
find . -maxdepth 1 -type f | while read line; do
# note: this is run a subprocess
process_line "$line"
done
source "$IPC"
echo "found_foo=$found_foo"