Wouldn't this line be more readable like this?
```perl
if($res->headers->content_type =~ m!^application/json(;\s+charset=\S+)?$!)
```