Thanks to all who replied. jcleland (with a slight refinement from grep) suggested the typical way for redirecting a stream. However that won't really work in this case as my brainfck instructions are transformed into hardcoded perl statements. greenFox's suggestion has the same problem.
Joost and dog andPony suggested two other modules. Of those IO::Scalar does the reverse of what I want i.e. it treats a scalar as a filehandle. Tie::Handle::Scalar on the other hand was perfect. The only stumbling block was that it is not part of the Perl core modules and asking people to install it just to run tests seems a bit extreme. Luckily the code is short enough that I could just include it verbatim in my test script. Normally this would be a maintainence problem
but i'm not even using all the features of the current module so it won't be a problem if my local copy goes out of sync with the upstream version.
Here is the actual code from my test script. See the Inline::brainfck thread to understand the interpolated Brainfck code.
$a = "\t";
tie *STDIN, 'Tie::Handle::Scalar', \$a;
my $b = , ;
ok ( $b == 9, ' Does , work?');
untie *STDIN;
$a = '';
tie *STDOUT, 'Tie::Handle::Scalar', \$a;
..
ok ( $a eq "\t\t", ' Does . work?');
untie *STDOUT;
$a = '';
tie *STDERR, 'Tie::Handle::Scalar', \$a;
#
ok ( $a eq "\$p = 1 \$m[\$p]= 9\n", ' Does # work?');
untie *STDERR;
--
જલધર