use strict; use warnings; use 5.014; my @strings = qw{ cabin prawn pail error reptile engine copy echo soap eskimo carpet emblem skunk }; say for map { substr $_, 8 } sort map { my( $type, $ord ); if ( m{r} ) { $type = 0; $ord = 0; } elsif ( m{^e} ) { $type = 1; $ord = ord substr $_, 2, 1; } else { $type = 2; $ord = 255 - ord substr $_, -1, 1; } pack q{NNa*}, $type, $ord, $_; } @strings;