my $attachment_name = $start_hour . "_" . $hour_count; print $cgi->header(-type=>"application/vnd.ms-excel", -attachment=>"$attachment_name.xls"); print $cgi->start_html(-title=>"Exported Excel results"); # Write the data print $cgi->end_html;