use warnings; use strict; use Email::Address; sub countdots { my @addrs = Email::Address->parse(shift); die "expected exactly one address" unless @addrs==1; my $x = (my $tmp = $addrs[0]->user) =~ tr/././; my $y = ($tmp = $addrs[0]->host) =~ tr/././; return wantarray ? ($x,$y) : $x+$y; } use Test::More; my @tests = ( ['test@gmail.com', 0, 1], ['test.test@gmail.com', 1, 1], ['test.test.test@gmail.com', 2, 1], ['test.test.test.test@gmail.com', 3, 1], ['test.test.test.test.test@gmail.com', 4, 1], ['test@foo.bar.com', 0, 2], ['test.test@foo.bar.com', 1, 2], ); plan tests => 2*@tests+1; for my $t (@tests) { my ($ad, $exp_x, $exp_y) = @$t; my ($got_x, $got_y) = countdots($ad); is $got_x, $exp_x; is $got_y, $exp_y; } is countdots($tests[0][0]), $tests[0][1]+$tests[0][2];