I ran your program, and the value I got for $! was
"no such file or directory". So I tried this program:
#!/usr/bin/perl
print $!;
Sure enough, same error message. Apparently $! starts off
defined; I don't know why, and I'd noticed before. So you
might just want to start things off with:
undef $!;