http://www.perlmonks.org?node_id=294293


in reply to Reset while loop to beginning of hash when using 'each'

according to the each perldoc page, you have to reset the each call or else it will always keep iterating from where you left off.

To reset the is says execute: keys %hash; so you need something like:
# reset each keys %{$self->{'residues'}{$modelCount}}; while( my ($res, $ats) = each %{$self->{'residues'}{$modelCount}} ) { if($ats eq $line){ do stuff to $line; last LINE; } }