use strict; use warnings; my @ID = qw(123 456 789 666); my @name = qw(Smith Doe Allen); my $line = join(' ', map { $ID[$_], $name[$_] } 0..($#ID < $#name ? $#ID : $#name) ); print "($line)\n"; #output: (123 Smith 456 Doe 789 Allen)