You might want to set
binmode STDOUT; at the beginning of your script, as you are printing a binary file (the image) to STDOUT. ;-)
Also, the non-capturing parens (
(?:)) in your RegEx don't do anything; you might as well remove them.
Hope this helped.
CombatSquirrel.
Entropy is the tendency of everything going to hell.