my @variables = $_ =~ m/<\?--(\S+?)-->/g; #### my @variables = $line =~ /<\?--(\S+?)-->/g; #### my @variables = /<\?--(\S+?)-->/g; #### for my $variable ( @variables ){ # replace the tag with the value of the variable # if there is one. s/<\?--$variable-->/$$variable/g if $$variable; }