$ perl -le'"aaaaab" =~ /[aA](?{ pos })[bB](?{ print $^R })/' 5 $ perl -le'"aaaaac" =~ /[aA](?{ pos })[bB](?{ print $^R })/' $