for (sort third_field ) { print "Record: $_"; } sub third_field { my $x = (split ' ', $a)[2]; my $y = (split ' ', $b)[2]; $x <=> $y; }