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 ... }