in reply to Parsing a Log file

If your log file are organized in that order, (I mean "WORKSTATION" and "exit code" come one by one and in a fixed order), then you can just use:
#!/usr/bin/perl use warnings; use strict; open my $fh, '<', 'log.txt' or die "cant open log.txt:$!"; my $workstations; while (<$fh>) { next if /^\s*$/; if (/(WORKSTATION\d+)/) { $workstations = "$1(Line $.)"; } elsif (/(User program exit code:\s*\d+)/) { print "$workstations $1(Line $.)\n"; } }

If "WORKSTATION.." is at the beginning of a line as it seems to be in your example, change the regex to ^(WORKSTATION\d+) which makes it better/faster to suit your problem. so does 'User program exit code:' line...

Regards

lihao(XC)