$r->err_headers_out->{'Content-Disposition'} ="attachment; filename=\"$csv_file\""; $r->headers_out->{'Content-Disposition'} ="attachment; filename=\"$csv_file\""; $r->headers_out->{'ABZZ-Disposition'} ="attachment; filename=\"$csv_file\""; $r->content_type('text/csv'); $r->set_content_length([stat $csv_fh]->[7]); $r->rflush(); And then send the file via this: $r->sendfile($pdf_file);