if( eval "\$regexp = qr/$_/;" ) { # Use regexp } else { warn "Regexp error with regexp '$_': $@"; }