While testing one of my Perl scripts I needed to have it build a source file for my C++ project. Instead of using a custom build step, which may not run if no other files changes, I decided to create a build rule for Perl scripts. It's still not perfect since it will always run the Perl script, but I got around that by adding intermediate file checking within the script itself. The build rule passes in the intermediate directory of the project as a parameter '-int $(IntDir)'.

Download Perl Script build rule

To add a build rule to visual studio, right click on your project and select 'Custom Build Rules...'
Image
In the next dialog do the following:
1. Click Find existing and locate the rules file to add.
2. Check the box next to the rule to enable it.
Image
That's it. By default the new rule will run before any files are compiled so if you are generating source files it should all work out ok. To prevent source files from always being marked as modified I create a test file in the intermediate directory to see when the target file was last changed. This only really works for me because I do want to monitor changes in the generated header file.