Word Count

#!/usr/local/bin/perl
#Count words in a string

$wordcount = 0;
$line = <STDIN>;
 chop ($line);
while ($line ne "") {
       
        @array = split(/ /, $line);
        $wordcount += @array;
        $line = <STDIN>;
	chop ($line);
}
print ("Total number of words: $wordcount\n");