my @list; my $file = q[/path/to/some/file]; my $regex = qr[your pattern]; open my $fh, "tail $file |" or die; while (<$fh>) { chomp; say "testing: $_"; push @list, $_ if ( $_ =~ $regex); last if (@list >= 2); } local $"="\n"; say "found: @list";