in reply to Capture error from one-liner

A possible workaround redirecting STDERR:
$ perl -i.bak -pe 's/AJZ/AZZ/g if /^AB/' foobar 2> error.txt ~ $ cat error.txt Can't open foobar: No such file or directory.
So you would just need to check if a non-empty error.txt file is created.