# Init vars $prev_xists = "0"; @output = ""; @lines = get_lines(); @outlines = calc_lines(@lines) sub get_lines { ...... #perl code for getting lines } sub calc_lines { for (@_) { #Split out your data from the line my ($date, $time, $epochSec, $dev, $ifIdx, $ifIn, $ifOut, $nul) = split ','; if ($prev_xists) { my $dTime = $old_epochSec - $epochSec; my $bps = ($ifIn + $ifOut) / $dTime; } else { my $bps = ""; } $old_epochSec = $epochSec; $prev_xists = "1"; my $new_line = "$date,$time,$dev,$ifIdx,$bps"; push @output, $new_line ; } return @output; }