sub file_expansion { my ($output, $input) = @_; my $test = $output; # For testing whether I need to append to an array or a scalar# while (<@$input>) { if (-e $_) { open (FILE, "< $_"); my @lines = ; foreach my $line (@lines) { $_ = $test; if (/SCALAR/) { $output .= $line; } else { push @$output, $line; } } } else { print "<>"; } } } @temp_fyle = "/home/monkey/list_of_commands"; (looks like below: interface blah ip address 1.2.3.4 255.255.255.255 ) &file_expansion(\$template,\@temp_fyle);