Depending on how line-oriented your XML is, that regular expression might find none, one or all matches.
See perlre on "greedy" - .* will match as much as possible, including an intervening </Last-Modified> tag if possible.
There are two approaches to fixing this. The easy approach is to read the whole file into memory and do the replacement directly:
perl -0777 -le 's!<Last-Modified>(.*?)</Last-Modified>!<Last-Modified> +`date ...`</Last-Modified>!ge' mydoc.xml
The saner way is to use one of the XML parsing modules, for example XML::Twig.
Also, I would look at Time::Piece or Time::Local for doing the time conversion instead of shelling out to the date program for every replacement.
In reply to Re: Global matching not working as expected
by Corion
in thread Global matching not working as expected
by ForeverLearning
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |