use strict; use warnings; $/=undef(); # make it read everything in the file into a scalar context my @words = split /the regexp/, <>; # now the size of the array given by $#words is one less than the wordcount