Column_1,Column_2 Name11,In Name21,Out Name31,In Name41,In #### use Data::Dumper; my $infile = file.csv; sub mainCSV { open (my $infile1, '<', "$infile") or die "Unable to open $infile: $!"; my %hash = (); while (my $line = <$infile1>) { chomp; $line =~ s/\s*\z//; my @array = split /,/, $line; my $key = shift @array; $hash{$key} = \@array; } my $size = scalar keys %hash; # explicit scalar context print "Hash size: $size\n"; # prints Hash size: xx print Dumper(\%hash); }