substring conversion (in Haskell). Can you beat this? Ok, I found myself with a nice little problem:

you will get from stdin a string. In this string you will find some hex colors (like #ff00dd). You must return the string with the colors inverted (#ff00dd inverted is #00ff11).

A sample input/output could be:

ascscasad #ff00ff csdcas dcs c#001122 #qq5500
ascscasad #00ff00 csdcas dcs c#ffeedd #qq5500


As I am proficient in Haskell, I tackled the problem with it. Came up with this code, and I think it's the best I can do. Do you see any way to improve it / a completely different way to make it shorter?

import Text.Regex.Posix ( (=~) )

main = getLine &gt;&gt;= putStrLn . f

f [] = []
f x = let (b, q, p) = x =~ "#[0-f]{6}"
          c = '#' : ['0'..'f'] ++ "#"
          a = zip c (reverse c)
          r = map ( (maybe '@' id) . (flip lookup $ a) ) q
      in b ++ r ++ f p


I am also interested to compare other languages to Haskell, so post in other languages are welcome, too!
Perl, 44 chars

Two different tweaks can get it to this length, one suggested by Primo:

s/#\K[\da-f]{6}/sprintf"%06x",~hex ff.$&amp;/eg


Another one by playing around with the /ee modifier:

s/#\K[\da-f]{6}/"sprintf'%06x',~0xff$&amp;"/eeg


Requires -p command line switch (1 char included in count).

Works for lower-case hex numbers (as in example).  An i switch added to the regex would make it work for upper-case as well (though not preserving the case of the original number).