define host{ use windows-server host_name serverA hostgroups 060202 alias 060202 contact_groups yu address 192.168.1.1 } define host{ use windows-server host_name serverA hostgroups 060202 alias 060202 contact_groups yu address 192.168.1.11 } define host{ use windows-server host_name serverA hostgroups 060202 alias 060202 contact_groups yu address 192.168.1.21 } define host{ use windows-server host_name serverA hostgroups 060202 alias 060202 contact_groups yu address 192.168.1.1 } #### define host{ use windows-server host_name serverA hostgroups 060202 alias 060202 contact_groups yu address 192.168.1.1 } #### open(NAG,"nagios") or dir $!; my $start = qr/^define/; my $end = qr/^\}$/; my @array; while () { if (/$start/ .. /$end/) { push @array, $_; } } foreach (@array) { if (/192.168.1.1/) { print $_; } }