in reply to do $n exist in grep?

Not that I'm aware of. But you can always DIY:

$ perl -E 'grep { /^..(A|B)./ and push @f, $1 } @ARGV; say @f' xxBxx y +yAyy BA $

🦛

Replies are listed 'Best First'.
Re^2: do $n exist in grep?
by LanX (Saint) on May 12, 2021 at 16:28 UTC
      or even easier

      DB<34> @a = qw/xxBxx yyAyy zzNzz/ DB<35> @N = map {/^..(A|B)./} @a DB<36> x @N 0 'B' 1 'A' DB<37>

      Hint: m// returns an empty list if there's no match

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

Re^2: do $n exist in grep?
by misterperl (Friar) on May 12, 2021 at 14:47 UTC
    nice , TY u got an UPVOTE!