system("ping $_ >/root/scripts/log.txt"); The above code works for me in Linux But in windows, the simililar code does not work system("ping $_ >c:\temp\log.txt"); By using, single cotes, i can use it like system('ping 10.56.1.1 >c:\temp\log.txt'); But my scripts requires this command to be used in a loop, but this doesn't permit to use scalar variable. system('ping $_ >c:\temp\log.txt'); So this command doesnt work