#!/usr/local/bin/perl use strict; use warnings; my $file = 'hosts.cfg'; open (MYHOSTS, $file); while () { my @hosts = split(/\n\n/); foreach my $host (@hosts) { print if ('$host' =~ m/(GRID)/); print if grep(/RMAN/, $host); } } close (MYHOSTS);