You need to use the /m modifier so that ^ can match the start of lines within your string. Otherwise it just matches the start of your string and not lines within it. Also, you might want to use the /x modifier so that you can comment your RE a little bit. Here's a snippet for you to modify as is your wont:

#!/usr/bin/perl -l $text = do { local $/; <DATA> }; print $1 if $text =~ / ^Total\s+Datafile\s+Size\s+MB\s* # header ^-+\s* # separator ^([\d.]+) # the number I want /mix; __DATA__ Total Datafile Size MB ---------------------- 73602.1406 Total Database Size MB ---------------------- 48107.7656 Total Free Space MB ------------------- 25462.8125
Update: Some other notes. I'm not sure why you're using local *FH; but if you have a modern perl, you can do something like this instead:

open(my $fh, $file_name) or die; my $text = do { local $/; <$fh> }; # slurp close $fh;

In reply to Re: Matching Across Lines by duff
in thread Matching Across Lines by mkb125

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.