The value of $! is not useful or defined when it's not checked immediately after a failed system call (which doesn't include system, which is really a macro for a combination of fork/exec/wait steps). So, you're getting bogus
results from a bogus operation -- not surprising. {grin}