http://www.perlmonks.org?node_id=182083


in reply to How can I write a function's output to a scalar?

As a general rule functions should always return a value not print that value out. Following this rule will avoid problems like this.

But if you don't have the option of modifying the function you'll have to do some trickery with STDOUT.