use strict; use warnings; use Data::Dumper; my %myHash; my @array = qw( sean connery george lazemby roger moore timothy dalton pierce brosnan ); print("The array is: @array\n"); for my $i (0..4) { print("\nElement number $i\n"); my ($key, $val) = splice @array, 0, 2;; print("The key is: $key\nThe value is: $val\n"); populateHash($key, $val, \%myHash); print"The hash at cycle $i is: ", Dumper \%myHash; } print Dumper \%myHash; sub populateHash { my ($key, $val, $hashref) = @_; print "In the function, the key is $key and the value is $val\n"; $hashref->{$key} = $val; }