$foo = /^#+/; # match against $_. a false '' since you never set $_ $bar = not $foo; # take the logical opposite, so always "1" $baz = qr/$bar/; # make a regep object from the contents matching "1" $one_line =~ m/$baz/; # returns true if $one_line has a 1