{ local $/ = '//'; while(my $record=) { my %values = $record =~ /^([-A-Z]+)\s+-\s+(.*)/mg; next unless exists $values{'UNIQUE-ID'} and exists $values{'ACCESSION'}; # Your code using $values{'UNIQUE-ID'} and other values here } }