if (! exists $OutSheets{$SheetName}) { # We don't have that sheet yet, create a new one my $Sheet = $OutWB->add_worksheet($SheetName); $OutSheetCache{$SheetName}{Sheet} = $Sheet; $OutSheetCache{$SheetName}{NextRow} = 0; } # Fetch the sheet and next available row from last time my $OutSheet = $OutSheetCache{$SheetName}{Sheet}; my $OutRow = $OutSheetCache{$SheetName}{NextRow}; . . . copy sheet data ... # Save the next available row for next time... $OutSheetCache{$SheetName}{NextRow}= $OutRow;