my $found = 0; while ($found < 2) { my $line = ; if ($line =~ /customer2/) { $found++; my @customer2_data = split(/=/, $line); print "$found- $customer2_data[1]"; } }