Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6908037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:30:36+00:00 2026-05-27T08:30:36+00:00

I am writing a perl program to extract lines that are in between the

  • 0

I am writing a perl program to extract lines that are in between the two patterns i am matching. for example the below text file has 6 lines. I am matching load balancer and end. I want to get the 4 lines that are in between.

**load balancer** 
new 
old
good
bad
**end**

My question is how do you extract lines in between load balancer and end into an array. Any help is greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T08:30:37+00:00Added an answer on May 27, 2026 at 8:30 am

    You can use the flip-flop operator.

    Additionally, you can also use the return value of the flipflop to filter out the boundary lines. The return value is a sequence number (starting with 1) and the last number has the string E0 appended to it.

    # Define the marker regexes separately, cuz they're ugly and it's easier
    # to read them outside the logic of the loop.
    my $start_marker = qr{^ \s* \*\*load \s balancer\*\* \s* $}x;
    my $end_marker   = qr{^ \s* \*\*end\*\* \s* $}x;
    
    while( <DATA> ) {
        # False until the first regex is true.
        # Then it's true until the second regex is true.
        next unless my $range = /$start_marker/ .. /$end_marker/;
    
        # Flip-flop likes to work with $_, but it's bad form to
        # continue to use $_
        my $line = $_;
    
        print $line if $range !~ /^1$|E/;
    }
    
    __END__
    foo
    bar
    **load balancer** 
    new 
    old
    good
    bad
    **end**
    baz
    biff
    

    Outputs:

    new 
    old
    good
    bad
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently writing a Perl program that is to read a given file (either
I am writing a Perl program that sends and receives messages from two sockets
Looking for help on writing a Perl program that takes an input file and
Perl is really good for writing the kind of string/file parsing programs that I
I am writing a Perl script (in Windows) that is using File::Find to index
I am writing a program to extract data from a bunch of text files
I'm writing a program in Ruby that downloads a file from an RSS feed
I'm writing a Perl program that will take a few command-line arguments (they'll actually
I'm writing a combination Java/Perl program that parses XML files into an Oracle SQL
My Perl program takes some text from a disk file as input, wraps it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.