use Regexp::Common qw( net ); while ( ) { while ( m/($RE{net}{ipv4}:\d+)/g ) { print $1, "\n"; } } __DATA__ [LAN access from remote] from 213.114.117.222:52582 to 10.0.0.3:5697, Monday, July 23,2012 19:42:26 #### while( m/(10\.0\.0\.\d+:\d+)/ ) { print $1, "\n"; }