use strict; my $contents = do {local $/; }; print get_chunk($contents); sub get_chunk { my ($contents) = @_; my $start = qr|========= Summary of bfpr_catfl results ===\s*|; my $end = qr|========= end ===\s*|; my ($chunk) = $contents =~ /$start(.*)$end/s; return $chunk; } __DATA__ you won't see this or this ========= Summary of bfpr_catfl results === you will see this and this ========= end === you won't see this or this or that