while (){ s/^(\d+): /$1,/; # convert first field seperator from ': ' to ',' my @fields = split /,/; next unless $fields[3] == 987; my ($hr, $min, $sec) = split /:/, $fields[1]; # do something with time here }