#!/usr/bin/perl -w use strict; my $sortname = shift; print join ' ', sort $sortname 1..20; sub num { $a <=> $b } sub alpha { $a cmp $b } #### % foo.pl num 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 % foo.pl alpha 1 10 11 12 13 14 15 16 17 18 19 2 20 3 4 5 6 7 8 9 #### SUBNAME may be a scalar variable name (unsubscripted), in which case the value provides the name of (or a reference to) the actual subroutine to use. In place of a SUBNAME, you can provide a BLOCK as an anonymous, in-line sort subroutine.