About Python, are there practical situations outside IRC where you can't include a newline in there? This ..
python -c '
import re, sys
for line in sys.stdin: print(line.lower().count("foo"))
'
works in shell interactively (both bash and zsh support multiline history entries well), or in shell scripts, and also in slack/mattermost/matrix/email.