#!/usr/bin/perl -T use strict; use warnings; use Scalar::Util qw(tainted); # Run this as "perl -T test.pl hello" or similar, so $var is "from outside" my $var = shift; # Uncomment the following line to untaint $var and see 'normal' behaviour of pos() # $var =~ /(.*)/; $var = $1; # Untaint blindly, don't do this in real code # Report whether $var is tainted or not print "Var is " . (tainted($var) ? "tainted" : "not tainted") . "\n"; # Odd behaviour only arises when tainted $var is in an array my @array = ($var); # If this matches, then pos() should be set to 1 $array[0] =~ /./gc and print "Match found"; # Check what pos() actually IS set to... my $pos = pos($array[0]) // 'UNDEF'; print "Pos is now $pos\n";