use CGI ':cgi'; # list of parameter names my @params = qw(city zip lastname country other obs); # extract all parameters into a hash my %param; foreach (@params) { $param{$_} = param($_); } # time passes... while () { foreach my $p (@params) { s/<\?--$p-->/$param{$p}/g if defined $param{$p}; # you'll probably want to print it too } }