# ... this is the part of the code I am trying to make work my $xp; # initialize parser object and parse the string $xp = XML::XPath->new( ErrorContext => 2 ); eval { $xp->parsefile( $open_this ); }; # $open_this is the xml file # report any error that stopped parsing if( $@ ) { $@ =~ s/at \/.*?$//s; # remove module line number print STDERR "\nERROR::: $open_this isn't well formated file:\n$@\n"; } ...