foreach my $atom (sort keys %residues{$residue}){ do something with $atom; } #### N CA C O CB CG CD1 CD2 CE1 CE2 CZ OH 2HB 3HB HD1 HD2 HE1 HE2 HH