# reading file into array and then process it # and write out to the same file: my $file = "./test.txt"; open (LOG, "+<$file"); flock LOG, 2; my @logfile=; seek (LOG, 0, 0); truncate (LOG,0); foreach my $line(@logfile){ # do some manipulations with $line... print LOG $line; } close LOG;