use warning; # needs to be use warnings; my $path = '/abc'; my $te = "$abc/texas"; # I assume you mean $path instead of $abc? my $mi = "$abc/michigan"; I assume you mean $path instead of $abc? my $ha = "$abc/hawaii"; I assume you mean $path instead of $abc? my $fl = "$abc/florida"; I assume you mean $path instead of $abc? my $ke = "$abc/kentucky"; I assume you mean $path instead of $abc? my $filename = "path/one.xls"; # needs to be my $filename = "$path/one.xls"; my $excl = Spreadsheet::WriteExcel->new($filename) or die "Cannot create new Excel file: $!" unless defined $excl; # this will not work my $workbook = Spreadsheet::WriteExcel->new('protected.xls'); # from module documentation (notice the ";" here) die "Problems creating new Excel file: $!" unless defined $workbook; # from module documentation # add the following after the part my $book = $parser->parse($source); for my $source ( '$te/te.xls', '$mi/mi.xls', # all files need to be defined with double quotes (e.g. "$te/te.xls") '$ha/ha.xls', '$fl/fl.xls', # with single quotes will not work '$ke/ke.xls' ){ my $book = $parser->parse($source); if ( !defined $book ) { die $parser->error(), ".\n"; } #### if ($source =~ /1/) { $file = $excl->add_worksheet('Texas'); }