open (FILE, "<" ,"datafile"); my $sent_date=""; while (<>){ my $this_date_range=""; ($sent_date)=/^Sent: (.*)$/; #Could be more precise, but you're only expecting one instance of Sent at the start of a line ? ($this_date_range)= /^\*{4}\s+Analysis Date Range\s+:\s(\d{2}\/\d{2}\/\d{4})/; add_to_spreadsheet($sent_date,$this_date_range); }