sub combine_rows { my ( $label, @arrays ) = @_; my @joined; for my $i ( 0 .. $#{$arrays[0]} ) { # assumes that all arrays are the same size push @joined, join( ';', $label, map { $arrays[$_][$i] } 0 .. $#arrays ); } return \@joined; } #### @ports = qw( portname portID port802 ); @val1 = qw( ON ON OFF ); @val2 = qw( EX EX NEX ); my $joined = combine_rows( "ports", \@ports, \@val1, \@val2 ); print "$_\n" for ( @$joined );