print join "\n", @rawentries[ # array slice to turn the indices back to the values (could use map, too) sort { ($rawentries[$a] =~ /Endbit/i) <=> ($rawentries[$b] =~ m/Endbit/i) # sort first using the index's array value matching against a regex and sort against the return. non-matches go higher; matches go lower || $a <=> $b # default to just sorting the index values to maintain order w/in bit/not-bit chunks } 0 .. $#rawentries # sort the indices ] ;