in reply to parse a log file

You might find it more clear to use regular expressions to parse the input. Properly constructed, they can be more forgiving of input format variations.

Your problem could be done in a single regex, but I'll break it down here for ease of understanding.

# grab the first two non-whitespace items, separated by whitespace. my ($date, $time) = $s =~ /(\S+)\s+(\S+)/; # grab the last two portions of the disk name, # which is immediately followed by the first ^ in the file. my ($disk) = $s =~ /\\(\w+\\\w+)\^/; # grab the user name, which is the string before the last ^, # which in turn is followed by some white space and the end of the str +ing. # You can take out the \s+ if the space between the ^ and end of strin +g was an artifact of your post. my ($user) = $s =~ /(\w+)\^\s+$/;
Note that in this example, it doesn't matter if the number of elements in the disk path changes - it will always grab the last two. In your example, a change in the path format would break both $disk and $user.

The same thing is true of the search for the user name. As long as it is the string before a ^ at the end of the line, it will always parse correctly with the regex, even if the format of what comes before it changes.

Regular expressions take some work to get used to, but that effort is well rewarded.