in reply to sorting array of hashes

This isn't all that hard - you just use a custom sort and prioritize your comparisons by checking for special values first. In this case I use a set of regexes as hash keys and provide a default (3) for the cases that aren't covered. This example steps on the values $aKey, $bKey, $aPri, $bPri - you could modify the code to eliminate the temporary variables.
%sort_priority = ( qr|^/etc/init.d| => 0, qr|^/root| => 1, qr|^/usr/bin| => 2, qr|.?| => 3 ); @new_array = sort { # Get the matching keys ($aKey) = grep { $a->{'path'} =~ $_ } keys %sort_priority; ($bKey) = grep { $b->{'path'} =~ $_ } keys %sort_priority; # and now their priorities $aPri = $sort_priority{$aKey}; $bPri = $sort_priority{$bKey}; # Now compare based on priority then value ($aPri == $bPri ? $a->{'path'} cmp $b->{'path'} : $aPri <=> $bPri) } @array;
Update: And of course I forgot that it's a bunch of hash references. Now $a and $b are properly dereferenced