http://qs1969.pair.com?node_id=324324


in reply to Storing Lines before and After pattern

Because of $` and $' overhead, this is an ideal place for split:
open ($fh, "<poem") or die "Couldn't Open!"; $poem = do{ local $/; <$fh> }; ($before, $match, $after} = split /(DOG)/, $poem;



Code is (almost) always untested.
http://www.justicepoetic.net/