The easiest way is to do it is in the shell. However, if you are looking to wrap an existing CGI script to check/filter its output before forwarding it on entirely in Perl, I would clone STDOUT and then redirect the original into a scalar for whatever inspection was appropriate/necessary. Cloning and redirecting is discussed in good detail in
.