It can be done as :
my $file_size=-s "folder/Excel_12345.xls" ; print $q->header( -type=>"application/vnd.ms-excel",
#MIME type
-attachment=> "folder/Excel_12345
.xls", -Content_Length=>"$file_size" #File size ); open (INFILE,"folder/Excel_12345.xls
" ) or die("FAILED TO OPEN Excel FILE"); binmode(INFILE); while (<INFILE>){ print $_; } close(INFILE); unlink ("folder/Excel_12345.xls
" ); #delete file from server exit;
It’s important that it should be written before printing the header. ie., print $q->header();