package MyOrder; use strict; # export junk goes here... my %order = ( # order hash goes here... ); sub SortMyWay { if ( exists $order{$a} and exists $order{$b} ) { return $order{$a} <=> $order{$b} } elsif ( exists $order{$a} ) { return 1 } elsif ( exists $order{$b} ) { return -1 } else { return $a cmp $b } } package main; use strict; # use the module with the sort stuff in it, # which also exports sub SortMyWay my @foo = ( # stuff to sort goes here... ); my @bar = sort SortMyWay @foo;