# # Arguments: # $a1 == reference to an array of scalars # $a2 == reference to an array of scalars # Returns: # an array of scalars that are the result of # prepending the contents of $a2 to the elements of $a1 # or undef if the number of elements of $a1 and $a2 # are not the same. sub prepender{ my ($a1,$a2)=@_; my @ax=@$a1; # Dereference only for clarity. my @ay=@$a2; # same as above return undef if $#ax != $#ay; return map { $ay[$_] . $ax[$_] } (0..$#ax); } # # Sample call my @array=('A'..'G'); my @array1=(10..($#array1+9)); my @array2=prepender(\@array,\@array1);