Sorry, but I don't understand the question.
- You haven't provided any sample input data, or the expected output for that input. See also How do I post a question effectively? and I know what I mean. Why don't you?
- Please use consistent indentation in your source code. See perltidy to help with that.
- Please provide a Short, Self-Contained, Correct Example: for example, the code from open (my $in ... up to close $it ; doesn't seem to have anything to do with counting words, and the last two blocks of code beginning with my $numlinepw and my $numlinenw seem to be pretty much identical except for the variable names, for the purposes of asking this question one of them can be removed, and in the final code should probably be refactored into a subroutine.
Having said all that, this looks suspicious to me: @nwords = split( /\n/, $nwt ); - @nwords will contain lines, not words, unless of course your input file only has one word per line - but again, you haven't shown it, so we don't know. (Update: And it's not just that - $nwt is a filehandle, as per jwkrahn's post).