perl -e '$string="apples and oranges are both fruit but I much prefer apples"; @count=$string=~m/apple/g; print "\nThere are ", scalar @count," occurrences of the word apple in the string\n";' There are 2 occurrences of the word apple in the string