in reply to A field comes empty

Sorry tl;dr but a quick glance shows that strict is missing and warnings are deactivated.

Please correct this and show us the resulting errors ... if any.

Additionally please try to create a SSCCE and provide sample data.

HTH :)

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

update

At second glance, my $valid_protein is scoped to the surrounding if-block, hence can't survive.

Please note: strict would have caught this !!!

Have a look at coping with scoping for the underlying mechanics.