#!/usr/bin/perl while (<>) { print if m/(\d+)\D+(\d+)/; print "$1\n$2\n"; } #### tm@norad:~$ ./regex_test 123 testing... testing 456 123 testing... testing 456 123 456