in reply to Looking for elegance

G'day monkprentice,

Here's another way to do it:

#!/usr/bin/env perl use strict; use warnings; my @data; map { /^\d+/ ? push(@data, $_) : ($data[-1] .= $_) } <DATA>; print sort { ($a =~ /^(\d+)/)[0] <=> ($b =~ /^(\d+)/)[0] } @data; __DATA__ 2 [...] [line1] [line2] [line3] 3 [...] [line1] 1 [...] [line1] [line2] 2 [...] [line1] [line2]

Output:

1 [...] [line1] [line2] 2 [...] [line1] [line2] [line3] 2 [...] [line1] [line2] 3 [...] [line1]

As well as looking at elegance, you might want to consider comparing whatever solutions are suggested for efficiency (with Benchmark).

-- Ken