use IO::Scalar; sub var_eval { local *FH; my $fh; tie (*FH, 'IO::Scalar', \$fh); $saved = select FH; eval shift; select $saved; $fh; }