#!/usr/bin/perl use v5.35.0; use List::Util qw(sum); my @input = map [split], <>; my @left = sort {$a <=> $b} map $$_[0], @input; my @right = sort {$a <=> $b} map $$_[1], @input; say sum map abs($left[$_] - $right[$_]), 0..$#input;