my ($marker, @pairs) = split; my $c = 0; while (@pairs) { ++$c; my ($thing1, $thing2) = splice(@pairs, 0, 2); print "$marker $c $thing1 $thing2\n"; }