#!/usr/bin/perl use strict; use warnings; use autodie; open my $h, '<', 'file.txt'; local $/ = ''; while (my $block = <$h>) { # split off header my $body = (split /==========\n/, $block )[-1]; # split on the long ***** line my ($before, $after) = split /\*{20,}\s*/, $body, 2; print "before: $before\n"; print "after: $after\n"; }