Another thing worth to mention is that, Perl actually counts input line numbers separately for each file handler. $. is just an alias for the input line number of the last accessed handler.
In case, you can not determine which file handler is the last accessed, or such a determination is not easy to make, you have to use input_line_number against a particular file handler.
A piece of code to demo those mentioned:
test.pl:
use IO::Handle;
open(MYSELF1, "<", "test.pl");
open(MYSELF2, "<", "test.pl");
while (<MYSELF1>) {
print "after reading from myself1: $.\n";
if ($. % 2) {
<MYSELF2>;
print "after reading from myself2: $.\n";
}
print "returned values from input_line_number: (";
print MYSELF1->input_line_number(), ", ";
print MYSELF2->input_line_number(), ")\n";
}
close(MYSELF1);
close(MYSELF2);