in reply to A regex question.

It seems to me that your problem is in your control mechanisms, specifically that your if statement should be inside of a while statement that goes through your data line by line. Also maybe a global variable to keep track of matches. If you're reading a file, then you'll have something like:

my $matches = 0; open FILE, ">filename.txt" or die $!; while (my $ethernet = <FILE>) {
if ($ethernet=~/eth1\.\d{4}\@/m){ ## do something matches++; } }

Replies are listed 'Best First'.
Re^2: A regex question.
by 1nickt (Canon) on Aug 01, 2015 at 14:42 UTC

    This won't work because you are opening the filehandle only for writing. In fact it will clobber the contents of the file.

    It should be:

    # open FILE, ">filename.txt" or die $!; #output only, and deprecated s +yntax open my $file, '<', 'filename.txt' or die $!; while (my $ethernet = <$file>) { ## do something }
    The way forward always starts with a minimal test.