in reply to Re^2: Regex - remove characters (pattern not terminated)
in thread Regex - remove characters (pattern not terminated)

The output I would like to see is: temp = 0

As whatever matches will be replaced, just include those 6 characters in the search pattern:

$temp =~ s/$pattern\w{6}//i;

As for the inversion, see reverse.