# create excel file my ($fh, $xls_filename) = tempfile(DIR => $tempfile_path, SUFFIX => ".xls", UNLINK => 1); my $xls_workbook = Spreadsheet::WriteExcel->new($xls_filename); my $xls_worksheet = $xls_workbook->add_worksheet(); ### inserting data into the worksheet $xls_workbook->close(); my $download_filename = "standard_filename.xls"; print "Content-Title: $download_filename\n"; print "Content-Disposition: attachment; filename=$download_filename\n"; print "Content-Type: application/octet-stream; file=$download_filename\n\n"; open(XLS, $xls_filename) or die "can't open temporary excel file: $!\n"; binmode XLS; binmode STDOUT; my $buff; while( read(XLS, $buff, 1024) ) { print STDOUT $buff; } close(XLS); exit(0); # exit for now - without refreshing the screen