The accepted awk answer by Alan is good, but here's a generic solution using xargs and bc. The idea is to generate a list of numbers in some way, use xargs to join them all on one line separated by spaces, and then use sed to change the spaces to + characters (tr would work too). pipe that into bc.
The same method can be used to construct a regexp from a list of strings/regexps, just change the spaces to | (extended regexp) or \| (basic regexp) instead of +:
for i in mydoc/* ; do pdfinfo $i ; done | \
awk '/^Pages/ {print $2}' | xargs | sed -e 's/ /+/g' | bc
NOTE: if there are many thousands of numbers generated, exceeding the shell's command line length limit, xargs may generate multiple lines. Since the output of bc qualifies as "generate a list of numbers in some way", the solution is to pipe the output of bc into xargs | sed -e 's/ /+/g' | bc again.
for i in mydoc/* ; do pdfinfo $i ; done | \
awk '/^Pages/ {print $2}' | xargs | sed -e 's/ /+/g' | bc | \
xargs | sed -e 's/ /+/g' | bc
xargs | sed -e 's/ /+/g' | bc | xargs | sed -e 's/ /+/g' | bc can, of course, be put into a shell script, function, or alias.
and here's an example of constructing a regexp using this method. If search.txt contains foo, bar, baz, quux (one word per line) then:
$ cat search.txt | xargs | sed -e 's/ /|/g'
foo|bar|baz|quux
the useless-use-of-cat is a place-holder for this example - replace with any pipeline that generates a list of words or regexp patterns.
If any of the search patterns contain space characters, you'll have to change them to something else (choose something not likely to be in the input) temporarily, before piping into xargs and then change them back again after the sed. e.g. if the 'bar' line of search.txt has a trailing space:
$ cat search.txt | sed -e 's/ /XXX_SPACE_CHARACTER_XXX/g' | xargs | sed -e 's/ /|/g' -e 's/XXX_SPACE_CHARACTER_XXX/ /g'
foo|bar |baz|quux