print "match failed\n" unless $string =~ m/(.+)\.BBB$/; print "dollar $1:\n"; #prints previous $1 value my ($thing) = ($string =~ m/(.+)\.BBB$/)[0]; print "thing =$thing\n"; #$thing is undef