... my $a = "whatever"; my $sort_sub = sub ($$) { $_[0] <=> $_[1] }; @arr2 = sort $sort_sub @arr1; ...