http://www.perlmonks.org?node_id=21486


in reply to Regex reset problem?

That is because you didn't reset your $template, so your regex didn't match %%DESCRIPTION%%. Use can use a tmp variable to reset $template.
open (TEMPLATE, "<$template_file") or die "Can't open $template_file: +$!"; $template = do { local $/; <TEMPLATE> }; close TEMPLATE; $tmp_template = $template; #store the template opendir (BIN, "$prod_dir") or die "Can't open $dir: $!"; while (defined ($file = readdir BIN)) { next if ($file =~/^\.\.?$/); #skip file starting with period +s open (DESCR, "<$prod_dir/$file") or die "could not open $dir +/$file: $!"; $description = do { local $/; <DESCR> }; $template = $tmp_template; # restore the template $template =~ s/%%DESCRIPTION%%/$description/; open (OUTPUT, ">$output_directory/$file.html"); print OUTPUT $template; close OUTPUT; next; } closedir (BIN);