#!/usr/bin/perl -w use strict; my @a = ("1-1-2", "6-1-2", "3-1-4", "1-1-1"); @a = sort{ my ($A_chapter,$A_sub_chapter,$A_verse) = split(/[-]/,$a); my ($B_chapter,$B_sub_chapter,$B_verse) = split(/[-]/,$b); $A_chapter <=> $B_chapter or $A_sub_chapter <=> $B_sub_chapter or $A_verse <=> $B_verse }@a; print "@a"; __END__ prints: 1-1-1 1-1-2 3-1-4 6-1-2