Perl can replace awk, sed, and grep for most cases, specifically when a multiline regular expressions is needed. For further help with this article, perl -help is your friend. Note common Perl sigils used in this article (@: arrays/lists). For deeper understanding: sudo apt -y install perl-doc (if Debian-based distros) or sudo yum -y install perl-Pod-Perldoc (RHEL-based). Then run perldoc perlvar Common one-liner flags a split the src text into @F array (part of the -F flag) e single line expression i in place replacement (a la sed) F split the src text using a delim (a la Awk’s fields) l new line separator (’\n’ by default) p print the result & execute on each line grep replacement echo -e "foo\nfoo bar" | perl -ne 'print if /^foo$/' sed replacement echo -e "foo\nbar foo" | perl -pe 's/^f(oo)/\1/' If you want in-place replacement: