in reply to problem count the number of words

Sorry, but I don't understand the question.

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).