Eg. Input file is like this: The "===" is the delimiter. ================================\n some buncha formatted ascii text\n some buncha formatted ascii text\n some buncha formatted ascii text\n ================================\n second buncha formatted ascii text\n second buncha formatted ascii text\n second buncha formatted ascii text\n ================================\n #### while(){ next unless ($_ =~ /$delimiter/) #look for the === push (@record, $_) #make a temp array &saveRecord(@record) #call the save sub } or while(){ next unless /$delimiter/ ... /delimiter/ while(#something){ push ... }