my $pattern = "----- blah de blah ----"; do_whatever($_) foreach split /$pattern/, join '', <> ; #### { local $/ = "----- blah de blah ----"; while (my $this_section = <>) { chomp $this_section; do_whatever($this_section); } }