template.html: %%insert_here%% sldfjkdslkf sdlfkjsdlf sldkjfdslk %%insert_here%% data.txt: hello foo.html: hello sldfjkdslkf sdlfkjsdlf sldkjfdslk hello #### use strict; my $htmlfile = "template.html"; my $datafile = "data.txt"; my $outfile = "foo.html"; my @cat1 = `/bin/cat $htmlfile`; my $cat2 = `/bin/cat $datafile`; open(OUTFILE, "> $outfile") || die "Can't open $outfile for write: $!"; foreach my $line (@cat1) { $line =~ s/%%insert_here%%/$cat2/ge; #maybe print OUTFILE "$line\n"; } close(OUTFILE);