That's the slowest way. See http://www.chengfu.net/2005/10/count-occurrences-perl/
heres a better way: $count = () = ($haystack =~ /$needle/g);
g - all occurrences =~ - find occurrences
() - count number of elements
how the f can you name a function () or =~? imagine googling perl () examples. in php it is substr_count, in python .count() and in perl? ()=++$p[][/%@//f/f/. if perl was low level programming language i could understand. but its not.