#!/usr/bin/perl -w use strict; my @unordered = ( '12 Corinthians 5:10', 'Hebrews 11:15', '1 Corinthians 13:23', '2 Corinthians 1:3', 'John 3:16', '1 Corinthians 12:10', '1 Corinthians 2:10', '1 Corinthians 2:10' ); my @ordered = map { $_->[0] } sort { for (my $x=1; $x<$#{$a}+1; $x++) { if (($a->[$x] =~ /\D/) || ($b->[$x] =~ /\D/)) { my $compare = $a->[$x] cmp $b->[$x]; return $compare if ($compare != 0); } else { my $compare = $a->[$x] <=> $b->[$x]; return $compare if ($compare != 0); } } return 0; } map { [ $_, split(/[ :]/) ] } @unordered; print join "\n", @ordered; exit;