use Sort::Key::Multi qw(s3_keysort); # s3 => three keys of type string my @lines = <>; my @sorted = s3_keysort { (split /,/)[3,4,5] } @lines;