Q:

Perl Regexp with an option

I am trying to parse this string and the number between /TN and ending forward /.  Also, if there is a /REF I need to grab the REF # as well. So it could be an either or situation.
Example String:
my $acis_string = 'EL41X/TN 333-3333 /DES TAT 313 223-2388 OE508-1-12-13/ORD R1244850301 /CD 02-03-15 /ZKMA 8001 T1ZF PNTCMINEDC0 PNTCMISOH00/SCS DQKUX /TN 333-3330, 6540/RTI 581 /LSO 248 340/REF 28/TGP 581 /ORD C1244888657/CD 02-12-16';

He was my base regexp:  
push @matches, [$2, $1] while $acis_string =~ /\/TN (.*?)\/.*?(\/REF (\w+)\/)?/g;

Desired Output:
$VAR1 = [
      [
        n/a,
        '333-3333 '
      ],
      [
        28,
        '333-3330, 6540'
      ]
    ];

Note:
There could be many /TN / and /REF in the string.
Thanks,
Kevin

A:

You can use the following regex:
\/TN\s+([^\/]+)(?:(?!\/TN|\/REF).)*(?:\/REF\s+([^\/]+))?

See RegEX DEMO
Explanation:

\/TN\s+([^\/]+) : Match characters other than / after /TN and put in capture group 1
(?:(?!\/TN|\/REF).)* : Logic to match characters making sure there is no /TN or /REF in them
(?:\/REF\s+([^\/]+))? : Optionally match characters other than / after /REF and put in capture group 2

