in reply to Trying to substitute a variable with another variable in a string but not working

It works for me when I print $string:
my $cell_name = "xyz"; while (<DATA>) { if (/STARTING_PATTERN\s+(.*)/) { $string = $_; $sub = quotemeta $1; $string =~ s/$sub/$cell_name/; print $string; } } __DATA__ STARTING_PATTERN RRR

Output:

STARTING_PATTERN xyz

Perhaps your input isn't as simple as RRR. If it contains regex metacharacters, use quotemeta, as shown.

Replies are listed 'Best First'.
Re^2: Trying to substitute a variable with another variable in a string but not working
by kaushik9918 (Sexton) on Feb 24, 2015 at 16:06 UTC
    quotemeta works fine. but the contents of the file are not modified. thanks for your time.