# set up an array at the top of your program my @output; # set up a flag my $capture = 0; sub cprint { $capture ? (print @_) : push(@output,@_); }