#!/usr/bin/perl # https://perlmonks.org/?node_id=1226079 use strict; use warnings; my $file = "t.txt"; local $/ = "NRG location"; open IN, "<", $file or die "IN: $!\n"; print /.*parameters after change\V*\n(.*\n)\V*NRG location/s while ;