#!/usr/bin/env perl -l use strict; use warnings; my %seen; for (qw{john.co.uk gim.com}) { ++$seen{get_first_part_of_address($_)}; } for (qw{john.com gim elephant.com banana}) { print unless $seen{get_first_part_of_address($_)}; } sub get_first_part_of_address { return (split /\./, shift)[0] } #### elephant.com banana