#! perl -slw use strict; my $buffer; while( ) { $buffer .= $_; # Accumulate lines in a buffer # Use \s+ instead of space to allow for newlines between words # The /g option is required to set pos() if( $buffer =~ /Content\s+Compression\s+to\s+Date/g ) { print "Content Compression to Date found"; # Once you find something your looking for # throw away everything that preceded it with substr() substr( $buffer, 0, pos( $buffer ) ) =''; } } __DATA__ Content Compression to Date other stuff other stuff other stuff Content Compression to Date other stuff other stuff other stuff Content Compression to Date Content Compression to Date other stuff other stuff Content Compression to Date other stuff other stuff