grashoper has asked for the wisdom of the Perl Monks concerning the following question:

I am not sure why this doesn't work, I am wanting to insert the label Date and a \n on each line that a date appears in my test files, so that I can populate a hash to insert into a db.
use strict; use warnings; my $text; while(<DATA>) { chomp($_); if($_ =~ /\d{1,2}\/\d{1,2}\/\d{4}/) { unshift($text .= "Date\n" unless $. == 1); $text .= $_; } else { $text .= "\n,".$_; } } print $text; __DATA__ 1/3/2007 12:20:01 AM Login,12.588309 SearchLoad,9.432586 SearchCount,20:0.196329 SearchResults,7.418672 SearchSave,3.616305 SearchDelete,2.066482 SearchDetails,6.873061 ClientAdd,0.784989 CMALoad,1.859894 CMASave,3.249620 CMADelete,0.450952 ClientDelete,0.305768 Logout,0.823402 1/3/2007 12:49:22 AM Login,10.958312 SearchLoad,13.644527 SearchCount,41:0.483233 SearchResults,7.027840 SearchSave,4.222601 SearchDelete,0.305821 SearchDetails,7.443877 ClientAdd,1.552915 CMALoad,1.202711 CMASave,5.285398 CMADelete,0.233119 ClientDelete,0.425521 Logout,0.560862