#!usr/bin/perl use strict; use warnings; use Data::Dumper qw(Dumper); local $/="\nCARS"; while (){ my @lines = split /\n/ ,$_; my ($manufacturer, $vendor) = $lines[0] =~m/^(?:CARS)?\s+(\w+)\s+(\w.+)/; print "----- Got car $manufacturer (Sold by $vendor) ---\n"; my @cars = grep {/^\+/} @lines; print "\tCAR: $_\n" for @cars; } __DATA__ CARS TOYOTO Etios Innova Camry +Fortuner Corolla *.This is Class cars. CARS HYUNDAI Verna i10 i20 +Eon Xcent +Tucson *.It is best cars. CARS HONDA City Brio Amaze +Accord *.This is Luxury cars. #### ----- Got car TOYOTO (Sold by Etios Innova Camry) --- CAR: +Fortuner Corolla ----- Got car HYUNDAI (Sold by Verna i10 i20) --- CAR: +Eon Xcent CAR: +Tucson ----- Got car HONDA (Sold by City Brio Amaze) --- CAR: +Accord