foreach $line (@data) { if ( ($line =~ /*disregard this*/)) { # If nextline date = previous line date # Append next line to current line # Else append the value 0 #### Data is here: Wed,Jun,13,10:40:35,2012 Wed,Jun,13,10:40:35,2012