http://qs321.pair.com?node_id=92069


in reply to What's like $+ but not gives the ordinal?

You might also have luck with @-, brand-new to 5.6.0 (it says here in perlretut).
$-[0] is the offset of the start of the last successful match. $-[n] is the offset of the start of the substring matched by n-th subpattern, or undef if the subpattern did not match. for (qw(foo bar baz)) { if (/(foo)|(bar)|(baz)/) { print "\$+ = $+\n"; print "\@- = " . join('/',@-) . "\n"; print "scalar \@- = " . scalar(@-) . "\n"; } } __END__ $+ = foo @- = 0/0 scalar @- = 2 $+ = bar @- = 0//0 scalar @- = 3 $+ = baz @- = 0///0 scalar @- = 4
which would seem to indicate that you could do $sub[scalar(@-)-2]->();, although I think I'd prefer something easier to understand, if I were going to maintain this.