my $i=0; # this variable will be visible in the foreach scope foreach my $name (@names) { next unless $name; ++$i; # autoincrement check_names($name); } say $i;