in reply to variable expansion

Something like this will do the trick:

my @lines = &read_all_lines_into_an_array(); # Here you set the values for the variables you want # interpolated later... eval qq{print "$_\n"} for @lines;
(Since this looks a lot like homework, I won't elaborate on the sub read_all_lines_into_an_array().

As perl will automatically interpolate the variables for you. However, this approach is *very* dangerous, as you would be trusting "code" coming from outside your script without proper sanity checking. Although the code would only go as far as a print, I would not consider this good programming practice. If you only care for simple scalar interpolation, you can probably do something along these lines:

for my $line (@lines) { for my $var ('@scalars_to_interpolate) { eval qq{\$line =~ s/\\$var/$var/g}, "\n"; } print $line, "\n"; }
Provided that you have a list of the scalars to interpolate.

Regards.