# File: defect1.pl use strict; use warnings; my $str = " xyz"; $str =~ /^(\s*)/g or die; print("match1: pos=", pos($str), "\n"); $str =~ /\G(\s*)/g or die; print("match2: pos=", pos($str), "\n"); $str =~ /\G(\s*)/g or die; print("match3: pos=", pos($str), "\n"); #### match1: pos=2 match2: pos=2 Died at defect1.pl line 13. #### use strict; use warnings; my $str = " xyz"; $str =~ /^(\s*)/g; my ($x) = ($str =~ /\G(x)/g) or die; defined(pos($str)) or warn("pos() is undefined!\n"); print("this should be x:$x\n"); #### pos() is undefined! this should be x:x #### use strict; use warnings; my $str = " xyz"; $str =~ /^(\s*)/g; my $x = ($str =~ /\G(x)/g)[0] or die; defined(pos($str)) or warn("pos() is undefined!\n"); print("this should be x:$x\n"); #### pos() is undefined! this should be x:x #### use strict; use warnings; my $str = " xyz"; $str =~ /^(\s*)/g; $str =~ /\G(x)/g or die; my $x = $1; defined(pos($str)) or warn("pos() is undefined!\n"); print("this should be x:$x\n"); #### this should be x:x #### This is perl 5, version 14, subversion 2 (v5.14.2) built for x86_64-linux-thread-multi