foreach @b { $hb{$_}++ } foreach @a { $ha{$_}++ } foreach keys %hb { push @c,$_ if ( not exists $ha{$_} ); }