3. Use lexical variables in the entire script, instead of using them sometimes throughout your script. Example ( $report_month, should be my $report_month) and then you can just call $report_month without using 'my' again.

4. You're chomping your variable data when you dont need to.

5. You're printing multiple header types which are confusing each other and is most likely your issue here.

6. You're printing plain html in your script, when you can just use the methods of CGI. See perldoc CGI..

Example of how I would change these things:

Code

Example of how I would change a few things.

#!C:\Dwimperl\perl\bin\perl.exe

use strict; use warnings;

use DBI; use File::Copy; use Excel::Writer::XLSX; use CGI qw( :standard ); use CGI::Carp qw( fatalsToBrowser );