I would use a hash which held references to arrays of arrays. You could use the first column as the key, and hold a reference to an array where each element is a reference to an array holding the data of each line that had that key. Sounds complicated, but isn't too bad once you get the hang of it.
heres some sample code:
#!/usr/bin/perl
use warnings;
use strict;
open FILE, "input" || die "Couldn't open file";
my %hash;
while ( <FILE> ) {
chomp;
my ( $key, @rest ) = split /,/;
foreach ( 0 .. 4 ) {
$rest[$_] = "" unless ( defined( $rest[$_] ) );
}
push @{ $hash{$key} }, \@rest;
}
# To print out every 1st row of all the ones beginning with QTY
print "$_->[0]\n" foreach ( @{ $hash{QTY} } );
# total number of entries for the category
print scalar( @{ $hash{QTY} } );
# print a specific row of data
print "@{ $hash{QTY}[2] }\n";
Update: Hehehe... looks like i was beaten to it... oh well... the more the merrier, right?