sub _split_options { my ($opts) = @_; while (my ($k, $v) = each %$opts) { print "$k = $v\n"; } print("\n"); while (my ($k, $v) = each %$opts) { print "$k = $v\n"; } } my %opts = qw( a 1 b 2 c 3 d 4 ); scalar each %opts; _split_options(\%opts); #### a = 1 b = 2 d = 4 c = 3 a = 1 b = 2 d = 4 #### sub _split_options { my ($opts) = @_; keys %$opts; # Reset iterator while (my ($k, $v) = each %$opts) { print "$k = $v\n"; } print("\n"); #keys %$opts; # Previous loop reset iterator while (my ($k, $v) = each %$opts) { print "$k = $v\n"; } } my %opts = qw( a 1 b 2 c 3 d 4 ); scalar each %opts; _split_options(\%opts); #### c = 3 a = 1 b = 2 d = 4 c = 3 a = 1 b = 2 d = 4