http://www.perlmonks.org?node_id=1052347

packetstormer has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks

I really struggle with Regular Expressions! I have been battling this for a while but can't figure it

I need to match a string between two double quotes then make changes to that matched string. However, it is proving difficult. See below, I capture the line between quotes into a variable then make changes to it. I then want to change that back in the line (to write out to another file later)

#!/usr/bin/perl use strict; open (FH,"test.test") or die; while(<FH>) { if ($_ =~ /"(.+?)"/) { print "Matched: $1\n"; } }
test.test looks like this:
This is line 1 "hello there" the is line 2 "goodbye, take care" this is line 3 "Jump, fox. Jump"
output:
Matched: hello there Matched: goodbye, take care Matched: Jump, fox. Jump
How do I modify $1 back into $_ to write out? I have tried assigning $1 to $new and then matching that on the original string but I can't figure it out!?