in reply to Regex error when [] occurs in file..

while (chomp(my $temp=<INPUT>)){
Don't do that. Do your chomp inside the loop. Otherwise, you'll get a warning (you do have warnings enabled, don't you?) when you reach the end and <INPUT> returns undef, since chomp expects a string, not undef.