use strict; use warnings; use autodie; $template_file_name="configtemplate.txt"; while(<>) { ($location, $hostname, $ip) = split (/,/); open(TFILE, "< $template_file_name") || die "config template file $template_file_name: $!\n"; $ofile_name = $name . ".txt"; open(OFILE, "> $ofile_name") || die "output config file $ofile_name: $!\n"; while () { s/##location##/$location/; s/##hostname##/$name/; s/##ip##/$ip/; printf OFILE $_; } } #### while(<>) { next if /^#/; ...