> ## Content Index
> Fetch the complete content index at: https://kudithipudi.org/llms.txt
> Use this file to discover other available public pages before exploring further.

# HOW TO : Simple perl script to replace lines in file
- URL: https://kudithipudi.org/how-to-simple-perl-script-to-replace-lines-in-file/
- Published: 2009-02-19T06:11:26.000Z
- Updated: 2009-02-19T06:11:26.000Z
- Description: Nothing fancy.. but here is a simple perl script to open a file, search for specific content in the a line and replace it with some...
- Author: admin
- Tags: HOWTO, Programming, Technology, Uncategorized, #wp, #wp-post, #Import 2026-08-23 02:32

Nothing fancy.. but here is a simple perl script to open a file, search for specific content in the a line and replace it with some other content.  
  
`open (SOURCE, "< source.xml") or die "Could not open file source.xml: $!\n"; open (DESTINATION, ">modfile.xml")  
or die "Could not open file modfile.xml: $!\n";`

while (defined($line =)) {  
if ($line =\~ m/YYYYYYYY/i) {  
$line = "XXXXXXXXXXXXXXXXXXX\\n";  
}  
print DESTINATION "$line";  
}

close (SOURCE);  
close (DESTINATION);  

You are opening a file named source.xml, reading every line and if there is some text that matches “YYYYYYYY”, you are replacing the whole line with “XXXXXXXXXXXXXXXXXXX”. I am sure there are more elegant ways to write this :).. but this will do the trick too..