#!/usr/bin/perl -w use strict; my (%brokers, $broker); # get file contents into an array for convenience open (CONFIG, "ubroker.properties") || die "Can't Open ubroker file: $!"; while () { next if /^#/; chomp; $broker = $_ if /^\[.*\]$/; # found a broker $broker = '' if /^\s*$/; # found a blank line # add line to current $broker if there is one $brokers{$broker} .= "$_\n" if $broker; } close CONFIG; # keys %brokers returns an array of brokers to iterate over for (keys %brokers) { print "\nBroker: $_\n"; # this is the broker name print $brokers{$_}; # this is the data (includes name) } #### @brokers = keys %brokers; @data = values %brokers;