Better to restrict apache's access to just the Perl command you need to run and not to Perl as a whole and not to root. Create a wrapper script around Perl for this. Create a new user or find a suitable one. In this example that user is bob:
EDITOR=emacs #or other favorite editor
visudo -f /etc/sudoers.d/apache_foobar #safe edit as root
Add this line, save and exit editor:
apache ALL=(bob) NOPASSWD: /the/path/myscript
Then put this in /the/path/myscript
#!/bin/bash
echo "Hello, I'm "`whoami` #should see bob
/usr/bin/perl -pi -e 's/foo/bar/g' "$1"
Replace "$1"
with /tmp/newxml.xml
if that's the only file you have to operate on.
The script only have to be readable+executable to bob, not apache or others:
chown bob:bobsgroup /the/path/myscript
chmod 500 /the/path/myscript
Now user apache should be able to run this as user bob in your php:
`sudo -u bob /the/path/myscript /tmp/newxml.xml`;
If bob is a newly created user for the purpose, you might have to add bob to /etc/shadow. (note: SELinux can cause trouble for this setup, but that's also solvable)