my $workbook; # No need for the = () my $worksheet; # No need for the = () # Create output file with user filename: if ($outfile ne "d") { $workbook = Spreadsheet::WriteExcel->new($outfile); # No my, or $workbook will go out of scope at the end of the if block $worksheet = $workbook->add_worksheet(); # same here print "What should we label the column containing the data?\n"; my $colname = ; chomp($colname); $worksheet->write(0,"A",$colname); } # Other code here I assume # Write 00 temperature data into file: $read = 4+(($day-1)*58); $temp = $xls->1{("B", $read)}; $row = $day + 1; $worksheet->write($row,$col,$temp); # No my $day = $day + 1;