#!/usr/local/bin/perl use strict; use warnings; while ( ) { next if ($_ !~ /bakjob(\d)_details/); print "bakjob$1:\n"; my $found = 0; while ($found < 2) { my $line = ; if ($line =~ /customer2/) { $found++; my @customer2_data = split(/=/, $line); print "$found- $customer2_data[1]"; } } } END; __DATA__ bakjob1_details = { credit = { customer1= 2000.0, customer2 = -1500.0 customer3 = 0.0, }, debit = { customer1= 50000.0, customer2 = -2000.0, customer3 = 0.0, } }, bakjob2_details = { credit = { customer1= 1000.0, customer2 = 200.0, customer3 = 500.0, }, debit = { customer1= 600.0, customer2 = 659.0, customer3 = 887.0, } } #### % testing.pl bakjob1: 1- -1500.0 2- -2000.0, bakjob2: 1- 200.0, 2- 659.0,