This does not directly address your question, but I can suggest that, since the bodies of your loops seem very similar if not identical, there is a way to more concisely express the requirement to loop through all passwords from '0000' to '9999' using the
sprintf built-in.
>perl -wMstrict -e
"for (0 .. 2, 103 .. 105, 9997 .. 9999) {
my $password = sprintf qq{%04d}, $_;
print qq{$password }
}
"
0000 0001 0002 0103 0104 0105 9997 9998 9999
You may also, in future, wish to consider enclosing large chunks of code in
<readmore> ... </readmore> tags; please see
Writeup Formatting Tips for more info. (You can even update your post to do this now!)
Update: It's also a good idea to check the return status of any file or network I/O operations and die or warn as appropriate.