Function to insert text after last match

Based on <http://unix.stackexchange.com/a/78573/3645>.