#!/usr/bin/env perl use strict; use warnings; my $define_re = qr{ \A define \s+ host \{ \s+ ( .*? ) \s+ \} \s* \z }msx; my $crit_dmz_re = qr{ (?> CRIT | DMZ ) }x; my $out_format = qq{%s (%s) in groups: %s\n}; local $/ = ''; while () { /$define_re/; my %block = ( split /\s+/ => $1 ); if ($block{hostgroups} =~ /$crit_dmz_re/) { printf $out_format => @block{qw{host_name address hostgroups}}; } } __DATA__ define host{ use HALF host_name denlas02 alias denlas02 address 146.xxx.xxx.xxx hostgroups LINUX,DEN,DMZ } define host{ use HALF host_name ppplas11 alias ppplas11 address 10.xxx.xxx.xxx hostgroups LINUX,PPO,ORAPRD } define host{ use ALIVE host_name ppplas12 alias ppplas12 address 10.50.33.26 hostgroups LINUX,GRID,RMAN,CRIT } #### $ pm_hosts_parse.pl denlas02 (146.xxx.xxx.xxx) in groups: LINUX,DEN,DMZ ppplas12 (10.50.33.26) in groups: LINUX,GRID,RMAN,CRIT