#!/usr/bin/perl use strict; use warnings; my @array1 = (1, 2, 3, 4, 5); my @array2 = (3, 4, 5, 6); my @nur_array1 = grep{my $i = $_; !grep{$_ eq $i}@array2}@array1; my @nur_array2 = grep{my $i = $_; !grep{$_ eq $i}@array1}@array2; print join(",",@nur_array1),"\n",join(",",@nur_array2),"\n";