use warnings; use strict; use OpenOffice::OODoc; use File::Copy; use Encode; my ($i, $my_text); my @Fnames = ('test.php'); # files to read into document copy "test.odt.tmpl", "test.odt"; my $doc_out = odfDocument(file => 'test.odt'); # setup output # ====== add files into output document ====== foreach(@Fnames) # process each php file { open(my $file, "<", $_) or die "Error reading $_: $!"; $my_text = ""; # init for (<$file>) { # \x{A0} is   s/^( +)/"\x{A0}"x(length($1))/e; $my_text .= $_; } $doc_out -> appendParagraph(text => encode('UTF-8',$my_text), style => "Default"); # write a full php file to odt } $doc_out -> save; # done