use strict; use warnings; my $string = "string"; if( $string m/([5]?)string/ ){ print "? inside group: $1\n"; #prints fine } if( $string m/([5])?string/ ){ print "? outside group: $1\n"; #Use of uninitialized value $1 in concatenation (.) or string... } return 0;