tie @array, 'Tie::File', $file or die ("Oh Noes cannot open $file"); for (@array){ if (/"$section"/){ $_ .="$newline"; last; } } untie @array;