I have a task to correct the syntax of xml files if they are not well formatted. Currently I am doing this task manually. Is there any way to validate the syntax of `XML` file, if XML is not well formatted then correct it to well formatted?

Is it possible to validate and correct with `Perl` script?

Thanks,