( categories: one liners | regular expressions )
The key is to do the match with the 'g' modifier in list context, then compare the result in scalar context to obtain the number of matches.
Example:
Print the lines in 'file.txt' that have the string 'for' repeated exactly 3 times:
perl -ne 'print if ( ( () = /for/g ) == 3 )' file.txt





