in reply to insert lines based on some pattern

By the term "order", do you mean similar ones should be grouped ?
If so, a quick solution can be
my %hash; for (@filenames) { chomp; push @{$hash{$3}}, $_ if ($_ =~ /(.+)\/(.+)\/(.+)\/.+/); } for (keys %hash) { print "#".uc($_)."\n" ; print $_."\n" for (@{$hash{$_}}); print "#END ".uc($_)."\n" ; }
This uses a hash. You can print the output to a file.

Replies are listed 'Best First'.
Re^2: insert lines based on some pattern
by CountZero (Bishop) on Feb 16, 2007 at 10:12 UTC
    If you look carefully at the sample output, you will see that the order of the files is maintained with files in the same type to be "surrounded" by "bakery" or "fruitjunction" tags.

    Your hash-of-arrays will not keep this "interleaved" order.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law