in reply to Appending values to variable.

my $newpath = join '\\', @dirs;
Or you could have just substituted,
$filepath =~ tr!/!\\!;
The doubled backslashes are needed because it is the escape character in perl quoting.

After Compline,
Zaxo