open(MAIL, "$file") || die "cant open spool\n"; my @mail_lines = ; close (MAIL); while ( @mail_lines ) { $_ = shift @mail_lines; if ( /^SYSDATAMSG$/ ) { # next three lines are needed $uname_data = shift @mail_lines; $uptime_data = shift @mail_lines; $time_stamp = shift @mail_lines; # (maybe you want to do things with those lines before/besides printing) print $uname_data, $uptime_data, $time_stamp; } }