in reply to uninitialized value in concatenation (.)

As written, $1 will receive the directory separator from (\\|\/) rather than the filename. Also, I find it a good practice to avoid using .* where possible. Finally, you need some sort of error handling for when the match fails.

Taking these three things into account, I would rewrite the two lines which extract the filename as:

$filename =~ m/^.*(\\|\/)([^\\\/]*)$/; my $newfilename = $2 || die "Filename $filename failed to match!\n";

(Although in the real world, you'd probably want to attempt to recover gracefully from the failed match rather than dying...)