use strict; use warnings; my @names; while (my $name = ) { chomp $name; # remove newline push @names, $name; } print "The third name is $names[2]\n"; my @copy = @names; # take a copy for the hash demo my ($i, $j, $k); while (@names) { for (\$i, \$j, \$k) { if (@names) { $$_ = shift @names; } else { $$_ = 'ran out of records'; # could use undef too } } print "i: $i j:$j k: $k \n"; } # and with a hash my %hash; while (@copy) { %hash = (i=>'', j=>'', k=>''); # clear the hash for my $key (qw(i j k)) { $hash{$key} = shift @copy if @copy; } print "the hash contains $hash{$_} under $_\n" for ('i'..'k'); } __DATA__ a b c d e f g h