"@QUERY:FOO" ...data... ...data... ...etc... "@ENDQUERY" "@QUERY:BAR" ...data... ...data... ...etc... "@ENDQUERY" #### while () { if ($_ =~ /^\"\@QUERY:(.*)\"/) { my $query = $1; my $i = 1; while ( !~ /^\"\@ENDQUERY\"/) { print $_; #$data{$query}->{$i}->{$_} unless ($_ eq ""); $i++; } } } #### Using perl 5.6.1 unless otherwise noted. Apache 1.3.27 unless otherwise noted. Redhat 7.1 unless otherwise noted.