in reply to uninitialized value in concatenation (.)

Regarding the first error (uninitialized value in concatenation at line 56), the previous replies are good, and I can suggest some other ways to do what you want:
# like this: (my $newfile = $filename ) =~ s{.*[\\/]}{}; # if there is no (back)slash, $newfile will be same as $filename # or like this: my @path = split /[\/\\]/, $filename; my $newfile = pop @path; # or use File::Basename, if that's appropriate to your needs
As for the second error (readline() on unopened filehandle at ... line 57) I would guess that line 57 is this one:
while(<$filename>) {
You are supposed to put an open file handle inside the "diamond" operator -- not a scalar string that holds the file name. Do something like this instead:
open( IN, $filename ) or die "$filename: $!"; while (<IN>) {