use Modern::Perl; while () { if ( !/\d/ ) { print; } else { say $1 while /(address.{13})/g; } } __DATA__ This is the list of address here are the addreses address 6433 main st address 6434 main st address 6435 main st #### This is the list of address here are the addreses address 6433 main st address 6434 main st address 6435 main st