What r u trying to solve. i am not sure why you have two while loops. Please let us know what is the input to it. What would be the output too. This could help us to get to resolve the problem that you face.As far us now i can just understand that you are replacing a pattern with another one that will have space and length of the pattern. Please let us knwo what you want clearly with a example so that we could help you.
Thanks
SasiKumar
Comment on Re: Replacing the pattern to search for
Actually the thing is that I want to retain the size of the code by inserting the space whereever that particular $pattern exists. The second while is used as there can be any no. of lines before there the pattern is found.
use strict;
my $file_name="c:\\temp.txt";
open (FH,"$file_name");
my $pattern="some thing";
my $c=0;
my $space=' ';
my $line;
while(<FH>)
{
$line=$_; #current line
$c++; #counts the number of lines
$space=' ' x $c .' ' x length($pattern); #pattern that has to be r
+eplaced
$line=~s/$pattern/$space/i;
}