grep has a quick solution which will probably work, but there's one thing to keep in mind. Filenames can have spaces in them, and this can break things. Maybe you want to search for the error message, like so:
my ($error) = /(INVALID.*)/;
Which should grab any error which begins with the text
"INVALID".
This, of course, presupposes that you do not have a file called "INVALID.FILE" or somesuch. Without modifying the reporting routine, you're forced to have some faith..
On the other hand, if you can be certain of the errors you are trying to trap, and their relevant formatting, you should probably try and extract the error rather than remove the filename. Give this a shot:
my ($error) = /(INVALID ORDER-NO \d+)$/;
Make sure you've
chomped accordingly.