Unquoted string "writefile" may clash with future reserved word at id.pl line 21 . Name "main::writefile" used only once: possible typo at id.pl line 21. Use of uninitialized value $Process1 in concatenation (.) or string at id.pl lin e 21. readline() on closed filehandle file3 at id.pl line 23.

The first problem is that you're manually parsing an xml file with a regex instead of using an XML parser. If the xml data is simple enough, then a simplistic regex approach can work, but is a very fragile approach.

Why are you opening "Process.out" in a loop? That doesn't make any sense.

$Process1 is declared, but never assigned a value, so attempting to open a filehande to "$Process1.out" isn't going to be very fruitful.

You should ALWAYS check the return code of an open call to make sure it was successful and take action if it wasn't. You can do that test explicitly on each open call, or you can use the autodie pragma which will do that check for you.

When opening a filehandle, you should use a lexical var for the handle instead of a bareword. The bareword writefile that you used for the handle is what the first error message is referring to. If you had written that in uppercase, perl would not have complained but you should use a lexical var instead.

Don't use the C style for loop syntax. It's cleaner and more efficient to use perl's for loop syntax.

Do you want to use the existing id numbers and just format them with leading zeros, or do you want as is implied in your code to replace them with a new sequential (formatted) number even if it's not the same value as the original?