#!/perl/bin/perl.exe -w use strict; my @data = ( ["1040564312", "IN", 258381720], ["1040564312", "OUT", 4194077715 ], ["1040564322", "IN", 258385268], ["1040564322", "OUT", 4194081727], ); foreach my $record (@data) { for my $i (0 .. 2) { print $record->[$i] . " "; } print "\n"; } #### 1040564312 IN 258381720 1040564312 OUT 4194077715 1040564322 IN 258385268 1040564322 OUT 4194081727 #### (i.e. 1040564312 - 1040564312 = 0), and then print the IN value followed by the OUT value so the output should be: #### 0 258381720 4194077715 0 258385268 4194081727