perl -e 'print qq!$_\n! for grep {length} map {s/.*(\d{7})/*$1/ ? $_ : q!!} @ARGV;' 1234567890 1234567 1234567890123 wibble 123