in reply to Quarms with RegEx

One problem here is the way you've set up your two while loops. The outer loop processes one line, then the inner loop processes all the remaining lines, then the program exits. This task can be accomplished with a single loop instead. Here's one way to do it:
my(%domains, $domain, @servers); while (<IN>) { chomp; if (s/^# *//) { if (defined $domain) { $domains{$domain} = [ @servers ]; @servers = (); } $domain = $_; } else { push @servers, $_; } } if (defined $domain) { $domains{$domain} = [ @servers ]; }
I also chomped the newlines and removed the '# ' from before the domains.