I'm trying to loop over the output of a Perl process, line by line, within a `while` loop. However, I'm having difficulty with the syntax.

I tried this, but got an "ambiguous redirect" error: 

```
#!/bin/sh

while read line; do 
    echo "$line" 
    # do stuff with $line 
done < $(perl process.pl)

./script.sh : line 6: $(perl process.pl): ambiguous redirect

```

For instance, one (inefficient) solution would be:

```
#!/bin/sh

tmpFile=/tmp/tmpFile.txt
perl process.pl > $tmpFile 
while read line; do 
    echo "$line" 
    # do stuff with $line 
done < $tmpFile

```

I know I can pipe the Perl process to a `while` loop as:

```
perl process.pl | while ...

```

but the while loop is executed in a subshell, and I need some variables set in the `while` loop to remain after the loop finished, so this is not an option.

What can I do?