I get the following from 'grep CAD currency.csv' created from the script below. If the file has more than one e-mail message in it (this one does) how can I get it to return the correct date along with the currency rates data (which are correct)? 2001-06-14,14:16:23,PDT,CAD,Canada Dollars,0.657776,1.52027 2001-06-14,14:16:23,PDT,CAD,Canada Dollars,0.656214,1.52389 2001-06-14,14:16:23,PDT,CAD,Canada Dollars,0.656039,1.52430 2001-06-14,14:16:23,PDT,CAD,Canada Dollars,0.651900,1.53398 2001-06-14,14:16:23,PDT,CAD,Canada Dollars,0.652010,1.53372 2001-06-14,14:16:23,PDT,CAD,Canada Dollars,0.652225,1.53321 The above dates should fall between 6/14 and 6/20. Thanks, Jack #!/usr/bin/perl # # cur2csv.pl # use strict; use vars qw($started); use vars qw($cur_sym $cur_desc $usd_unit $units_usd); use vars qw($year $month $mday $hour $minute $second $timezone); use vars qw($conv_date $date $time $tz); use Date::Manip; use String::Strip; use DBI; use DBD::Pg; open (OUTFILE, ">", "currency.csv") || die "Can not open currency.csv for writing"; printf STDERR "Reading currency file..."; open (INFILE, "/var/spool/mail/currency") || die "Can not open /var/spool/mail/currency for reading"; while (<INFILE>) { # Extract date and time of Currency Rate Quotation ($year, $month, $mday, $hour, $minute, $second, $timezone) = /^Rates as of (\d+).(\d+).(\d+) (\d+):(\d+):(\d+) (\w+) (.*)$/; # Convert date from UTC (GMT) to PST8PDT and adjust date and time accordingly. $tz = &Date_TimeZone; $conv_date = "$year-$month-$mday $hour:$minute:$second"; $conv_date = &ParseDate($conv_date); $conv_date = &Date_ConvTZ($conv_date, $timezone, $tz); $date = &UnixDate($conv_date,"%Y-%m-%d"); $time = &UnixDate($conv_date,"%H:%M:%S"); $tz = &UnixDate($conv_date,"%Z"); $year and last; # If we've matched the data line, then bail out. eof and print STDERR "Didn't find the date line"; } # Extract the ISO 4217 Code for Currencies and Funds (1995) # Extract the Currency Description, and trim the trailing spaces # Extract US Dollars to Units rate, and trim the leading/trailing spaces # Extract Units to US Dollars rate, and trim the leading/trailing spaces while (<INFILE>) { ($cur_sym, $cur_desc, $usd_unit, $units_usd) = /^([A-Z]{3})\s+([A-Za-z()\s]{28})\s+(\d+\.\d+)\s+(\d+\.\d+)/; # Strip the trailing spaces from $cur_desc StripTSpace($cur_desc); $cur_sym and $started++; if ($cur_sym) { printf OUTFILE "%s\,%s\,%s\,%s\,%s\,%s\,%s\n", $date, $time, $tz, $cur_sym, $cur_desc, $usd_unit, $units_usd; } } $started or print STDERR "Didn't find a currency line"; close(INFILE); close(OUTFILE); print STDERR "\n"; 1;