in reply to HTML image tag stripping

while($htmlLines[$i] =~ m/<IMG\s+([^>]+)>/ig)

$i has not been declared within that block. This is probably where your error is coming from. It is certainly not doing what you want. How about:

foreach ( @htmlLines ) { # do stuff with $_ }

But as I am sure others will point out that parsing HTML with your own regex's is dangerous, and will break sooner or later.
Use one of the HTML::* CPAN modules instead, click here for a list.
Also, note that:
for my $i (0..@htmlLines-1) { print $htmlLines[$i]; }
may be re-written as  print for @htmlLines
Hope this helps
--
bm