use strict; use diagnostics; while( ) { my @list = (); if( @list = ( $_ =~ m|^rs://([-\w]+)(?:\.([-\w]+))+|) ) { print join( ' > ', @list ), "\n"; } } __DATA__ rs://a rs://b.c rs://d.e.f rs://g.h.i.j.k #### b > c d > f g > k #### b > c d > e > f g > h > i > j > k