How to do search and replace operation on a portion of a string in perl
I recommend reading this article to know more about usage of substr function in perl. Basically substr function and a typical search and replace mechanism (s///g) can be combined to achieve the goal in a single statement.
Look at the following script which replaces the word “goes” to “moves” in first first 10 characters of a string variable “$str”.
#!/usr/bin/perl $str="What goes around comes around"; print $str . "\n"; substr($str,0,10) =~ s/goes/moves/g; print $str . "\n";
Output of the above script is as follows:
[neo@techpulp ~]# perl replsubstr.pl What goes around comes around What moves around comes around [neo@techpulp ~]#
You can play with substr as explained in this article to select various range of characters in the string.

