tie @lines, 'Tie::File', $file or die "Couldn't open $file: $!"; for (@lines) { # actually modify the contents of the file s/66/$goodrow->{ClientID}/g; s/0906\s406\s2427/$SIMCard/g; } untie @lines;