use strict; use warnings; my ($ex, $ex1, $ex2, @test); my $length = 14; for $ex1 (1..15) { for $ex2 (5..15) { push @test, 'a' x $ex1 . '@' . 'b' x $ex2; } } for (@test, ) { chomp; if (length($_) > $length) { $ex = length($_) - $length + 3; @_ = split /@/; if (length($_[1]) > $ex) { substr($_[1], length($_[1]) - $ex, $ex) = '...'; } else { $ex += 3; $ex2 = length($_[1]) - 1; $ex1 = $ex - $ex2; if ($ex1 < 4) { $ex1 = 4; $ex2 = $ex - $ex1; } substr($_[0], length($_[0]) - $ex1, $ex1) = '...'; substr($_[1], length($_[1]) - $ex2, $ex2) = '...'; } $_ = join '@', @_; } print "$_\n"; } __DATA__ ted@dingos.com mary@supercalifradulistic.org i.am.a.purple.dinosaur@barney.must.die.com