in reply to how to make first element of an string as a the array name

You might want to tell us a little more about the problem you are trying to solve because your current solution is almost never the right way to do it.

It seems most likely that what you really need is a hash. Consider:

use strict; use warnings; use List::Compare; my $fileData = <<DATA; IL12::1::287,6,-17,-9,-21,-24,-15,-2,11,4,4,-15,-26,-16,-9,-18,-25,27, +17,6, IL12::1::329,-25,-18,-28,23,17,1,-3,-23, IL12::1::1108,-8,-21,17,-25,9,-6,-15,4, IL12::1::1536,-12,-28,23,-12,17,-25,14,19,20, IL12::1::1591,-17,-23,-7,-19,25,25,-25,-15,-26,23,29,-12,-25, IL12::1::803,24,-20,-24,12,8,-22, DATA my %items; my $referenceItem = 'IL12::1::287'; open my $inFile, '<', \$fileData; while (<$inFile>) { chomp; my ($item, @values) = split ','; $items{$item} = \@values; } for my $key (sort keys %items) { next if $key eq $referenceItem; my @common = List::Compare->new ($items{$referenceItem}, $items{$k +ey}) ->get_intersection (); print "Common for $key: @common\n" if @common; }

Prints:

Common for IL12::1::1108: -15 -21 -25 17 4 Common for IL12::1::1536: -25 17 Common for IL12::1::1591: -15 -17 -25 -26 Common for IL12::1::329: -18 -25 17 Common for IL12::1::803: -24

Perl is environmentally friendly - it saves trees