# code not tested! my $srcFile = "/path/to/file.ext"; open F, "<", $srcFile; # this trip is READ my @data = ; # this can be danger if you have a big file close F; open F, ">", $srcFile; # this trip is WRITE foreach my $line ( @data ) { $line =~ s/your_regex/expected_replacement/; print F $line; } close F;