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