use warnings; use strict; my $in_section=0; while (my $line = <>) { chomp $line; if ( $line =~ /^Success.*Id-9952895b108957daeb296ba4/i ) { print "$line\n"; $in_section = 1; } elsif ( $line =~/^Success/ ) { $in_section = 0; } elsif ($in_section) { print "$line\n"; } }