in reply to replacing text in multiple files

First of all I want to thank everyone for helping with the first error I was having. I was able to get the code cycling through the files, however now I'm running into an error doing a regex substitutions.
#Find the CHAN pair if( $UNID[1] eq $UNID[$x] ) { #Temporary variable to store the CHAN $channel2 = $CHAN[$x]; #Creates a loop counter $y = 1; #Tracks if the changes have been complete $complete = 0; #Search the files for the instancs of the CHAN while( ( $y < scalar( @FILES ) ) && ( $complete == 0 ) + ) { #Open the file for replacement open $fd, '<', $FILES[ $y ]; #Creates a backup of the original file $^I = '.bac'; @file = <$fd>; seek $fd, 0, 0; print "$channel1 and $channel2\n"; foreach $file ( @file ) { $file =~ s/$channel2/$channel1/ or die $!; } #Close the file that was searched close $fd; $y++; }#End replacing while #Remove the used entries from the array delete $CHAN[1]; delete $UNID[1]; delete $CHAN[$x]; delete $UNID[$x]; #Force the loop to end $found = 1; }#End pair find if
For some reason the line containing the studstitution errors out saying the variables are uninitialized. But I can put a print statement directly before them and that will print the values just fine. If I a use an or die statement I recieve an error just saying that the program died. Any help would be greatly appreciated. Thank you.