open (IN, 'file.txt'); my $out = ''; my $newComment = 0; while () { if(($newComment < 1) && ($_ ne /^\#|^--|^\/\/^\s*\/\*/|^\s*\*|\*\/$/)) { $out .= "#This file was updated with the fix"; $out .= "\n"; $newComment++; } $out .= $_; } open (OUT, '>output.txt'); print OUT $out or die "Can't print to OUT: $!"; close OUT; close IN; __DATA__ /* * This is the new function * It has the following parameters: * * 1. Filename * 2. URL */ # All the following are valid comment styles: # hello perl style -- hello sql style /* hello c style * continue c style end c style */ // c++ c style #Revision date: 2005-10-10 --start of file <-- here is where the new comment should go. configurationtype=search url=http://www.google.com --End of file