call a subroutine when the beginning of record is seen
It may work if the first and last
record are supposed to be processed by the sub, but what if the final line is supposed to be processed by some other piece of code? You can't just ungetc a readline...
Also, note that your process_record is making use of a global variable, DATA, and three of your four examples will throw an undef warning if the end-of-file is reached before the closing line is seen.
I think a state machine type approach would be better, because it is more flexible and can handle the above cases specially, if needed.