in reply to search a string and get the output that belongs to the string

Here's another way (very similar to the first reply, but a little simpler):
#!/usr/bin/env perl use strict; use warnings; my @message; while (<DATA>) { push @message, $_; if ( /quarantine/ ) { # this is the last expected line of each me +ssage local $_ = join( "", @message ); local $\ = "\n"; print if ( /<jay@/i ); @message = (); } }