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


in reply to Insert into string

Hello

You did 2 mistakes in ur coding. That is:

1. Your variable name is wrong. $strFile variable not contains any text. so do change it to $src.

2. ? missing in <record (.*)>

$src ='<?xml version="1.0" encoding="UTF-8"?><record name="rightnav" t +ype="content"><item name="RHS_Image"><value>/me/accounts/include/imag +es/accounts_RHS.jpg</value> </item> <item name="RHS_Navigation">'; $new_tag ='<item name="abcd"><value>'; if($src =~ /<record (.*?)>/igm){ $src=~ s/$&/$&$new_tag/i; } print "\n$src";

Output:

<?xml version="1.0" encoding="UTF-8"?><record name="rightnav" type="co +ntent"><it em name="abcd"><value><item name="RHS_Image"><value>/me/accounts/inclu +de/images/ accounts_RHS.jpg</value> </item> <item name="RHS_Navigation">