open my $fh, '<', \$output or die $!; while (<$fh>) { #... } close $fh or die $!;