in reply to Arrays and regular expressions

given what you've said I'd try something like this:
#!/usr/bin/perl use strict; open IN, 'file'; open OUT, ">outfile"; my %HASH = (); my @RUNNING = (); my $INSIDE = ""; # keep track of where we are while(local $_ = <IN>) { chomp; if(/^\s*$/) { # we have an empty line $HASH{$INSIDE} = @RUNNING if $INSIDE; @RUNNING = (); # empty running now that its c +opied $INSIDE = ""; # no longer inside anything next; # keep going } elsif(/^\s*(pos\s*\=\s*\d+)$/i) { # this should be the "header" $INSIDE = $1; next; } elsif($INSIDE) { push @RUNNING, $_; } } close IN; for(sort keys %HASH) { print OUT "$_\n", map { $_ .= "\n"; } @{$HASH{$_}}; } close OUT;
*shrugs* it passed strict and warnings.. but is untested.. also, if you're opening a BIG textfile.. IE megs large.. you might run into problems.. it'd get a tad more complex to fix that duplicate records problem with a large file but look at seek(), tell() and keeping records of where you are at the begining of each "id" in the OUT file.. have fun..

-brad..