When used with a filetest (-X) operator the stat structure of the previous file test is used
If any of the file tests (or either the
statorlstatoperator) is given the special filehandle consisting of a solitary underline, then thestatstructure of the previous file test (orstatoperator) is used, saving a system call.
…
Example:stat($filename); print "Readable\n" if -r _; print "Writable\n" if -w _; ...
So in your example !-d _ tests whether the file last stat-ed isn’t a directory.
Update
The unusual _ is really a typeglob *_ but with operators expecting a filehandle the * may be omitted, like <*STDIN> may be written as <STDIN>. It is found in the symbol table
print *{$main::{_}}{IO}, "\n"; # --> IO::Handle=IO(0x2311970)
In a one-liner the *_ gets set up only after calls to stat and _ are made.