Assuming your resources permit you to slurp the file, you could change the pattern to /.{1,}pattern/. The {1,} forces as many matches to '.' as possible, ensuring that the pattern is matched at its last occurrence.
Not knowing the type processing, you may need to open the file in a separate handle with the record separator left alone.