$ perl -n -e '$count++ while /\bhello\b/g; END { print $count }' text.out #### $ perl -n -e 'print, $count++ while /\bhello\b/g; END { print $count }' text.out