$i = 0; @users = map(/(\S+)\s+/g, grep { if(/-+\s/) { $i = 1; 0; } else { (/The command/) and ($i = 0); $i; } } `net user`); open(REPORT, ">lstlgn.txt") || die "Unable to open output file lstlgn.txt $!"; print REPORT "Last Logon Report\n". "-----------------\n\n". "Username Last Logon\n". "-------- ----------\n"; foreach $user (@users) { @lastlogon = map(/Last logon\s+(\S+\s\S+\s\S+|Never)\s+/, `net user $user`); write(REPORT); undef @lastlogon; } close(REPORT); format REPORT = @<<<<<<<<<<<<<<<<<<<<<<<<@<<<<<<<<<<<<<<<<<<< $user, $lastlogon[0] .