my $flag = 0; while ( ) { chomp; if ( /pattern/ ) { $flag = 1; next; } next if ! $flag; # what you want to do goes here }