use warnings; use strict; use Tie::File; my @file; my $template = 'test.dat'; my $o = tie @file, 'Tie::File', $template, recsep => "\r\n"; $o->flock; my @array = @file; untie @file; open (WRITE, ">test.dat"); foreach (@array) { if (/one/) { print WRITE "foo\n"; } } close WRITE;