in reply to sort by field

Sort by first name (untested):
@names = sort @names;
Sort by last name, using ST (untested):
@names = map $_->[0], sort { $a->[1] cmp $b->[1] } map { (my $x=$_)=~s/(\w+)\|(\w+)/$2,$1/; [$_,$x] } @names;