use Internals qw[ SetReadOnly ]; my %hash; undef @hash{ qw[ the quick brown fox ] }; SetReadOnly( \%hash ); ... while( <$fh> ) { if( ... some capturing regex ... ) { $hash{ $1 } = $2; } elsif( ... regex ... ) { $hash{ $1 } = $2; } else { $hash{ fox } == FOX_DEFAULT; } last if keys %hash == grep defined, values( %hash ); ## Updated, see below. }