in reply to Using pos() inside given/when

You've fallen into the "broken things added to Perl since 5.008" trap. Specifically, given/when uses lexical $_, which is a misfeature. You're best off avoiding "features" added to Perl since about 5.006.
Just another Perler interested in Algol Programming.