#!/usr/bin/perl -w use strict; my @data; while (){ my @dataline = split (/\s+/,$_); print "@dataline\n"; push(@data,\@dataline) } print "\n@data\n\n"; &printarray(\@data); print "\n"; my @data_sorted_by_four_fields = sort { $a->[2] <=> $b->[2] || $a->[0] <=> $b->[0] || $a->[4] <=> $b->[4] || $a->[1] cmp $b->[1] } @data; &printarray( \@data_sorted_by_four_fields ); print "\n"; ###########################################3 # Print the contents of the array sub printarray { my $aref=shift; foreach my $record (@$aref) { for my $i (0..4) { print $record->[$i] . " "; } print "\n"; } } ############################################# __DATA__ 1040564312 z 89 Out 4194077715 1040564322 w 90 Out 4194081727 1040564335 x 94 IN 4194085256 1040564335 y 94 Out 4194085196 1040564312 z 89 In 258381720 1040564322 z 90 In 258385268