use strict; use warnings; my $arg = 1220; my $switch; my @result; # here the touchstone or yardstick # start the comparison with a reasonably big number $result[0] = 10 ** 6; while (){ $switch = 1 if /^Status\s+id.*name$/; next unless $switch; next if /^[\-]+$/; chomp; my @fields = split /\s+/; if ( $fields[1] =~ /^\d+$/ and $fields[1] > $arg and $fields[1] < $result[0] ){ @result = @fields[1,0,-1]; } } # reset if nothing found undef @result unless $result[1]; print join ',',@result; __DATA__ date:17/4/2000 version: 4.1.0 -more info- -more info- ------------------------------------------------------------------ Status id not important info (two columns) name ----------------------------------------------------------------- Run 1234 @ ... foo1 Err 1235 @ ... foo1 Wait 54123 @ ... foo2 -----------------------------------------------------------------