perl -Fhello -0777 -lane 'print $#F' /tmp/hh # shorter: perl -apFhello -0777e '$_=$#F' < /tmp/hh # with check for word boundry (e.g. to exclude "Othello" or mispelled "cello") perl -apF'\bhello\b' -0777e '$_=$#F' < /tmp/hh