$regex = qr/(?{print "Hey!";})/x; $string = "some word"; $string =~ /some($regex)/;