Yes, you can sort with a custom rule. But what exactly is the rule for the sort? If you cannot work out a formal specification of the sort, no one will be able to do it "correctly".
The following gives the same ordering as you mentioned, but there is no guarantee that it is going to give you the "correct" ordering (as you might expect) for other input values:
Code:
use Data::Dumper;
@A = qw(cd1 a1 ef a2 hij a12 b2 b4 b22);
print Dumper([sort {
my ($_a, $_b);
for ([$a, \$_a], [$b, \$_b]) {
$_->[0] =~ /^(.+?)(\d*)$/;
${$_->[1]} = [$1, $2];
}
($$_a[0] cmp $$_b[0]) || ($$_a[1] <=> $$_b[1]);
} @A]);