open my $fp, \'<\', $file or die $!; while (<$fp>) { my $line = $_; if ($line =~ /$regex/) { # How do I find out which line number this mat
Don't use $., nor $_ or any global variable. Use this instead:
$.
$_
while(my $line = ) { print $line unless ${\*FILE}->input_line_number == 1; }
To avoid this and a lot of others Perl gotchas you can use on Atom or VSCode packages like linter-perl. Stop making Perl a write-only language!