foreach $heading (@headings) { print $heading; print "".shift(@names) for 1..10; # the "". might not be needed, cant remember :-) }