in reply to matching keyword in multi-line records

Clearly the code snippet you gave is incomplete. The problem here is probably that you have entries that span multiple lines. If the data is (and always will be) relatively small, the easiest way is probably to just load everything into an array. When the line starts with whitespace you would add it to the end of the previous entry, and otherwise you would start a new entry. Then you can go through the array with grep or foreach to find what you want. This is especially useful if you need to do multiple searches, as file operations are slower than in-memory ones. Something like this:
my @stuff; while (<>) { if (/^\s/) { $stuff[-1] .= $_; } else { push @stuff, $_; } } print grep { /keyword/ } @stuff;
If the data are large though, that would gobble up too much memory. In that case I'd go for something more like this, especially if you just need to do the search once:
my $last_entry; while (<>) { if (/^\s/) { $last_entry .= $_; } else { print $last_entry if $last_entry =~ /keyword/; $last_entry = $_; } print $last_entry if $last_entry =~ /keyword/ && eof(IN); }