... my $response_body; # # open the file for reading and writing # open( my $fileb, "+>", \$response_body ); $curl->setopt( CURLOPT_WRITEDATA, $fileb ); ... # rewind the file handle seek $fileb, 0, 0; while( <$fileb> ) { print $_; }