in reply to Parsing Text into CSV

The following code will give you the desired output:
#!/usr/bin/perl -w use strict; my %users; my $username; while (<DATA>) { next if (/^\s*$/); chomp; if (/^Username\:\s+([A-Z]+)\s+Owner\:\s+(.*)$/) { $username = $1; $users{$username}{realname} = $2; } elsif (s/^(Last Login\:\s*)//) { ($users{$username}{i}, $users{$username}{ni}) = split /,/, $_; } else { die "line invalid - $_, $!\n"; } } foreach my $user (keys %users) { print "$user,$users{$user}{realname},$users{$user}{i},$users{$user}{ +ni}\n"; } __DATA__ Username: JANDERSON Owner: JOE ANDERSON Last Login: 14-JAN-2002 08:14 (interactive), 4-MAR-2002 17:09 (non-in +teractive) Username: PBARRETT Owner: PAUL BARRETT Last Login: 18-JAN-2006 08:14 (interactive), 24-MAR-2005 17:09 (non-i +nteractive)

Comments:

I should also note that the above code is quite fragile, insofar as it assigns the $username when it reads the first line, and then assumes that the username is the same when it gets to the second line. There are probably much better ways to go about this, which no doubt some other monks will point out :)

Cheers,
Darren :)