open my $ifh, '<', $filename or die "$filename: $!"; chomp( my @array = <$ifh> ); close $ifh; # modify @array here open my $ofh, '>', $filename or die "$filename: $!"; print $ofh $_,"\n" for @array; close $ofh; #### use File::Replace; my $repl = File::Replace->new($filename); my $infh = $repl->in_fh; while (my $line = <$infh>) { chomp($line); # modify $line here print {$repl->out_fh} $line, "\n"; } $repl->finish;