Replacing XML tag values This function replaces some XML tag values. The tags appear in the XML exactly once.I want to know if this can be done in a better way.

sub editConnConfig{
my ($DOMAIN,$rscDir,$walletDir,$DEFAULTPORT)=@_;
`perl -pi -e 's!&lt;trustStore&gt;.*?&lt;/trustStore&gt;!&lt;trustStore&gt;$walletDir/fctrust.jks&lt;/trustStore&gt;!sg' "$rscDir/ConnectionConfig.xml" 2&gt;&amp;1`;
`perl -pi -e 's!&lt;keyStore&gt;.*?&lt;/keyStore&gt;!&lt;keyStore&gt;$walletDir/fckey.jks&lt;/keyStore&gt;!sg' "$rscDir/ConnectionConfig.xml"`;
`perl -pi -e 's!&lt;keyStorePassword&gt;.*?&lt;/keyStorePassword&gt;!&lt;keyStorePassword&gt;jkspass1&lt;/keyStorePassword&gt;!sg' "$rscDir/ConnectionConfig.xml"`;
`perl -pi -e 's!&lt;directoryName&gt;.*?&lt;/directoryName&gt;!&lt;directoryName&gt;$DOMAIN&lt;/directoryName&gt;!sg' "$rscDir/ConnectionConfig.xml"`;
`perl -pi -e 's!&lt;dbDaemonPort&gt;.*?&lt;/dbDaemonPort&gt;!&lt;dbDaemonPort&gt;$DEFAULTPORT&lt;/dbDaemonPort&gt;!sg' "$rscDir/ConnectionConfig.xml"`;
}
First and foremost, XML is not a regular language, and therefore parsing it using regular expressions is not appropriate, and is asking for trouble. 

Secondly, invoking perl within perl is clearly an awful idea. Invoking it multiple times is even worse.

As all the s!!! operations are performed on the same file, you could perform all of them at once in the same process, by separating them with semicolons, that is:

perl -pi -e 's!pattern1!replacement1!sg; s!pattern2!replacement2!sg' file


But as I said earlier, you should not call perl from within a perl function in a backtick expansion, but implement properly the operations (open file, read buffer, perform replacements, overwrite the file).

And instead of doing this using regular expressions, consider using an XML parser.