Get filename from output and assign to variable

I need to be able to take the following output (which changes dynamically, and issues several thousands of records), and get the filename, and assign it to a variable $fn:

TYPE:
filename2.tif:
TIFF Directory at offset 0x4aac
  Bits/Sample: 1
  FillOrder: lsb-to-msb
  Document Name: "Standard Input"
  Image Description: "converted PBM file"
  Orientation: row 0 top, col 0 lhs
  Samples/Pixel: 1
  Rows/Strip: 2376
  Planar Configuration: single image plane

I need to get "filename2.tif:" and assign it to a variable $fn.  The filename will always be different, so that's why I need it in a variable, and I'm sure a regex will need to be written to satisfy this.  The script is in a while loop, however, it is outputting multiple times.  Also, I want the above output to remain the same, I just want to take the filename and ALSO store in a variable (so no output will change).

Thanks in advanced.
if (/^\s*filename3.tif:$/) {
                $fn = $1;
                next;
}

## What I have so far, but doesn't work, obviously, since I need it to match all forms of filename.  Basically, it will be any form of letters and numbers followed by .tif: (yes, that's a colon at the end)

Open in new window

LVL 2
drewrockshardAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

deiaccordCommented:
You should be able to change the regex to the below and get it work


/^\s*(.+)\.tif:\s+$/i

if (/^\s*(.+)\.tif:\s*$/i) {
                $fn = "$1.tif";
                next;
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
drewrockshardAuthor Commented:
This worked beautifully. :) Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.