use Excel::Writer::XLSX; #Create a filehandle that just points to a scalar for now. my $excel_data = ""; open( XLS_TMP_FH, \$excel_data ); #Call the workbook constructor my $workbook = Excel::Writer::XLSX->new( \*XLS_TMP_FH ); #... #Chose if you want to save it if( i_want_to_save_it() ) { open( XLS_FILE, ">", "myfile.xlsx" ) or die( "Cannot open file: $!" ); print XLS_FILE join( "", ); close XLS_FILE; } close XLS_TMP_FH;