use Test::More; my %tests = ( 'hello' => 1, '{hello}' => 1, 'hello}' => 0, '{hello' => 0, 'oh {hello} there' => 1, 'oh {hello there' => 0, 'oh hello there' => 1, 'oh hello} there' => 0, ); plan 'tests' => scalar keys %tests; while ( my ( $text, $result ) = each %tests ) { my $hello = qr/hello/; my $test_result = ( $text =~ / \{$hello\} # hello with braces | # or (?