#!/usr/bin/perl use strict; use warnings; my $file = '/path/to/file'; open my $fh,"<",$file or die $!; local $/ = "\nAA"; while(my $entry = <$fh>){ my @lines = split /\n/,$entry; if($lines[0] =~ /Mercedes/){ print $_,"\n" for @lines[3,4]; } } close $fh;