tie my @lines, 'Tie::File', $ut_fh;#$ut_fh is a file handle for (@lines) { if (/.*USER\s+NOTE.*/i){ $_ .= "\n@$global_variables_list\n"; last; } }