while (defined( my $line = )) { if ($line =~ /^(AC|OS|OX|ID|GN)\s+(.*)/) { print "<$1> $2\n"; } } __END__ ARF1_PLAFA Reviewed; 181 AA. Q94650; O02502; O02593; Name=ARF1; Synonyms=ARF, PLARF; Plasmodium falciparum. NCBI_TaxID=5833; #### #!/usr/bin/env perl use warnings; use strict; my $filename = "uniprotfile"; open my $ufh, "<", $filename or die "open $filename: $!"; while (<$ufh>) { chomp; my ($id,$content) = /^(AC|OS|OX|ID|GN)\s+(.*)/ or next; if ($id eq 'AC') { my ($first) = $content=~/^([^;]+)/ or die "couldn't parse '$content'"; print "AC: $first\n"; ... } elsif ($id eq 'OS') { ... } ... }