#!/usr/local/bin/perl -w use strict; my @sorted=sort_file('data.txt'); my $cnt=0; my $size=@sorted; while ($cnt < $size) { print "$sorted[$cnt][0] is of type $sorted[$cnt][1] - $sorted[$cnt][2]\n"; $cnt++; } exit(); sub sort_file{ my $filename = shift; open DATA,$filename|| die "Unable to open file $filename :$!\n"; my @record; my $row =0; while () { chomp; #create Array one element per field my @line=split /,/; # move values into multi-dimensional array $record[$row][0]=$line[0]; $record[$row][1]=$line[1]; $record[$row][2]=$line[2]; $row++; } return (sort { $a->[0] <=> $b->[0] } @record); }