in reply to Data Structure

This smells like homework, so you can use this working solution if you can explain or re-write it.
echo "Student Id Class John 23 2 Mark 33 3 Jerry 44 2 Sam 55 2 Tom 65 3 " | perl -ane '$F[2]=~/^\d+$/ or next;push @{$h[$F[2]]},$F[0]}{ $h[$_] + && print qq|Class $_ = |,join(",",@{$h[$_]}),qq|\n| for 0..$#h'
Output:
Class 2 = John,Jerry,Sam Class 3 = Mark,Tom
UPDATE: FWIW, the Data structure used in the code above is an "Array of Array(ref)s".
The code posted below this node uses a Hash of array refs.

        "Software interprets lawyers as damage, and routes around them" - Larry Wall