# I didn't copy the top of your file, and you should add use Data::Dumper; if you want this code to work my $header = $csv->getline($FH); my @keys = @$header; my %result; while (my $row = $csv->getline($FH)) { my %currentRow; @currentRow{@keys} = @$row; print "Current row: ", Dumper \%currentRow; my $uniqueKey = "$currentRow{Amount} & $currentRow{AmountId} & $currentRow{MRP}"; # Bad idea if '&' is allowed in either of those values if(!exists $result{$uniqueKey}) # If this combinaison is unknown { $result{$uniqueKey} = [\%currentRow]; # save the current row to it } else { push @{ $result{$uniqueKey} }, \%currentRow; # add the current row to the ones with the same ID } } print "Result: ", Dumper \%result;