Can I break my Perl regex into multiple lines in my code?

Viewed 7623

I was just wondering if I am able to break up a long regular expression that I have in my Perl code so that it is written over several lines? I just want the readability and compactness to be intact for anyone that might view my code after its completion. I am looking for something analagous to the way in which strings are broken up over several lines in Perl. For example:

print "This is a string that is ". #1st line
      "very long, so it is on 2 lines!"; #2nd line
# prints = "This is a string that is very long, so it is on 2 lines!" 

I am not sure how to do this with a regex since it does not use quotes. If I press enter I am guessing it will put a new line character in my regex making it erroneous. I would like to do something along the lines of:

if($variable_1 = /abcde_abcde_abdcae_adafdf_      #1st regex line
                 abscd_casdf_asdfd_....asdfaf/){ #regex continued
    # do something
} # regex looking for pattern = abcde_abcde_abdcae_adafdf_abscd_casdf_asdfd_....asdfaf
3 Answers
Related