#!/usr/bin/perl use strict; use warnings; my $file = $ARGV[0] || 'foo.txt'; open(my $fh, '<', $file) or die "Unable to open '$file' for reading: $!"; my $buffer = ''; while (<$fh>) { if (/^\S+domain\.com$/) { process_buffer($buffer); $buffer = $_; next; } $buffer .= $_; } sub process_buffer { my ($section) = @_; print "================BLAH================\n$section\n"; }