use strict; use warnings; use Test::More tests => 4; my $re = qr/(?:#(\S+))?/; ok 'bli bla' =~ $re, 'No hash, matched'; is $1, undef, '$1 undef'; ok '#foo bli bla' =~ $re, 'With hash, matched'; is $1, 'foo', '$1 is foo';