ACTION_PATTERN='perl$' ROWS=$(perl -n -e '$count++ if /'$ACTION_PATTERN'/; END { print $count }' ~/.zsh_history) echo "ROWS:${ROWS}"