You could add a loop constraint to your if
statement. For example:
$sr = New-Object System.IO.StreamReader(Get-Item C:\Temp\a.txt)
$limit = 3; $i = 0
while ($line = $sr.ReadLine()) {
if ($line -match "London" -and $i -lt $limit) {
$line
$i += 1
}
}
would limit the number of lines returned containing "London" to whatever you set the $limit
variable to (in this case, up to the three first line matches found would be returned).