use strict; use warnings; my $test = 'DATA'; my @test_1_data = test_1($test); my @test_2_data = test_2($test); sub test_1{ read( DATA, my $foo1, 0x04 ); read( DATA, my $foo2, 0x04 ); read( DATA, my $foo3, 0x04 ); read( DATA, my $foo4, 0x04 ); return ( $foo1, $foo2, $foo3, $foo4 ); } sub test_2{ for(0 .. 3){ read( DATA, my $foo1, 0x04 ); read( DATA, my $foo2, 0x04 ); read( DATA, my $foo3, 0x04 ); read( DATA, my $foo4, 0x04 ); return ( $foo1, $foo2, $foo3, $foo4 ); #should return "belongs to sub_2" 4 times } #for a total of 0x10 in length each loop } print ( "\nsub test_1:\n" ); print $_ for(@test_1_data), "\n\n"; print "sub test_2:\n"; print $_ for(@test_2_data), "\n"; #should print "belongs to sub_2" 4 times on the same line. __DATA__ belongs to sub_1belongs to sub_2belongs to sub_2belongs to sub_2belongs to sub_2 #### sub test_2{ my @array; for(0 .. 3){ read( DATA, my $foo1, 0x04 ); read( DATA, my $foo2, 0x04 ); read( DATA, my $foo3, 0x04 ); read( DATA, my $foo4, 0x04 ); push (@array, ($foo1, $foo2, $foo3, $foo4 )); #push to array while inside of for loop } return (@array); #return it after all loop iterations are complete }