Software >> Development >> Languages >> Perl >> RegExp >>  How to write a search and replace script

use File::Basename; $prog = basename(replacebegin:content:replaceend); if($#ARGV < 0) { die "\nUsage:\t$prog <filename> <oldpattern> <newpattern>\n\neg.\t$prog 11111111 00111111\n\n"; } $filename = $ARGV[0]; $oldpattern = $ARGV[1]; $newpattern = $ARGV[2]; $buf = ""; open(inhandle,$filename); while(<inhandle>) { s/$oldpattern/$newpattern/gi; $buf .= $_; } close(inhandle); print $buf; open(outhandle,">$filename"); print outhandle $buf; close(outhandle);