I believe this code will work. I assume that the filename is the last thing on the line so I split on the :/ after the drive letter (notice it handles both types of slashes) and then it substitutes spaces anywhere after that in the string:
#!/usr/bin/perl -w
use strict;
+
while(<DATA>)
{
my @line=split /(:[\\\/])/;
$line[2]=~s/ /_/g;
print join "", @line;
}
__DATA__
124334 2323 c:\program files\somefile
124334 2323 c:\program files\somepath\somefile
124334 2323 c:\program files\with space/somefile
124334 2323 c:\program files\with space/with another space/somefile
HTH