use Template; use Excel::Template; sub xml_to_excel { my ($template_conf, $file, $hashref) = @_; # template configuration from config file, filename based on request number, data for the template processing my $xml; my $tt = Template->new({ RELATIVE => 1, # in my case I had to use relative path because of $template_conf->{file} based on CWD. }); $tt->process( $template_conf->{file}, $hashref, \$xml ) || die $tt->error; # write the output to the $xml string open my $xml_fh, "<", \$xml; # create a filehandle from the $xml string so that Excel::Template can read it. my $ET = Excel::Template->new({ file => $xml_fh, # use the filehandle here }); $ET->write_file($file); return $xml || 0; }