use strict; use warnings; use WWW::Curl::Easy; my $curl = new WWW::Curl::Easy; $curl->setopt(CURLOPT_URL, 'http://cnn.com'); my ($r, $b, $h) = get_response($curl); print "retcode = $r\n"; print "body = $b\n"; sub get_response { my ($curl) = @_; my ($body, $head); open(my $body_fh, ">", \$body); open(my $head_fh, ">", \$head); $curl->setopt(CURLOPT_WRITEDATA, $body_fh); $curl->setopt(CURLOPT_HEADERDATA, $head_fh); my $retcode = $curl->perform; return ($retcode, $body, $head); }