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