use IO::Scalar; my $output = <new(\$output); print while <$scalar_fh>; __output__ this is the first line and this is the second line but this is the last