#!/usr/bin/perl use strict; my (%record, $key); while () { chomp; if ( /^[A-Z]/ ... /]\n[A-Z]/ ) { ($key) = /(\S+)/ if ( /^[A-Z]/ ); push( @{ $record{$key} }, $_ ) if ( !/^[A-Z]/ ); } } print "$_: @{ $record{$_} }\n" for ( keys %record ); __DATA__ TxNum Band: 3 [10-30] [50-80] [100-200] RxNum Band: 3 {100-120} [120-300] [400-600] [800-1000] Others: 2000