use File::Temp qw(tempfile); my ($fh, $filename) = tempfile(); close $fh; system("your_command | tee $filename"); # then open $filename for reading, it contains the output