or download this
# Maybe this. I think I'd rather just access $+[0] directly.
my $start = $str =~ /a/g ? pos $str : 0;
my $end = $str =~ /b/g ? $-[0] : 0;
my $length = $end > $start ? $end - $start : 0;
my $ext = $length ? substr( $str, $start, $length ) : undef;