#!/usr/bin/env perl use strict; use warnings; use feature qw(say); use List::Util qw(first); my $rec_no = 0; my @record; my $msisdn; while(<>){ chomp; if(/^## $ ./t.pl Found record: 1 Record 1: MSISDN = 1234567890 this case is found here ..... Found record: 2 Record 2: MSISDN = 1234567890 this case is found here .....