in reply to How to perform different sorts on multiple sections of items in the same array

Maybe this is what you mean?
use strict; use warnings; my @array = qw(toad frog frig frag crow creep hop); my @sorted; for (@array) { if ( $_ =~ m/.*r/g ) { push( @sorted, $_ ); } } print "$_\n" for sort(@sorted);
Output:
creep crow frag frig frog
EDIT: Missed the point of this might being a homework assignment. apologies

Replies are listed 'Best First'.
Re^2: How to perform different sorts on multiple sections of items in the same array
by GrandFather (Saint) on Dec 30, 2014 at 04:03 UTC

    The .* is not required in your match expression nor is the /g. The whole loop can be replaced by:

    my @selected = grep {/r/} @array;

    Note that neither version of the matching code actually performs a sort so the variable name is more appropriately 'selected' than 'sorted'.

    Perl is the programming world's equivalent of English