#! perl -slw use strict; my @fields = ( '1234', '01234567890', 'abcd1234xy', '012 345 6789', '+44(0)1234 567890', ); for (@fields) { (my $new = $_) =~ s[\D+][]g; print "Old:'$_' New:'$new'??" if length $new != 4 and length $new != 10; }