$str =~ /Hulk hate (\w+)/k; #### if ($str =~ /Hulk hate (\w+)/k) { $str='demons!'; print $1; # could and probably would throw fatal error. }