tie *HACK, 'IO::Scalar', \$data;
print HACK <STDIN>;
*STDIN = *HACK;
Now if you don't destroy anything, reading from STDIN gives you what is already in $data which is what was in STDIN.
The idea was good but apparently copying tied stuff like that does not maintain the tie. (I shoulda known that, sorry.) Try this code instead:
$data = join '', <STDIN>;
tie *STDIN, 'IO::Scalar', \$s;
print STDIN $data;
I tested this by adding
after it, running it, and typing into it.
My apologies for the initial mistake.