in reply to reading file

This is SwissProt format, right? There exist a number of existing SwissProt tools on CPAN. Have you investigated any of them? If they are not sufficient for your needs, then you could try peeking at their source code to see how they handle parsing.

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'