in reply to sorting an array

I'm just guessing as to your intention, but if you mean that each element will hold an array ref of middle elements, try the following:

use strict; my @array = qw/ ***1*** first second ***end1*** ***2*** third fourth * +**end2*** /; my @new_array; foreach my $element ( @array ) { my $mark = quotemeta "***"; my $where = ( $element =~ /$mark(\d+)$mark/ .. $element =~ /${mark +}end$1+$mark/ ); push @{$new_array[ $1 - 1 ]}, $element if $where != 1 and $where ! +~ /E/ ; } use Data::Dumper; print Dumper \@new_array;

Output from above snippet:

$VAR1 = [ [ 'first', 'second' ], [ 'third', 'fourth' ] ];

If you want the array elements to hold a concatenated string, change the push to a concatenation.

Cheers,
Ovid

Vote for paco!

Update: Fixed stupid little useless loop that chipmunk alerted me to :)

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.