use strict; use warnings; while (){ my $input = $_; if ( ## are you sure the format is correct? $input =~ m/^(\w{3}) ## match 3 alphanumerics at the start [^\d]* ## non digits in the middle (\d+) ## capture all the digits before \. ## an actual dot /x ){ my $site_code = $1; my @rs = split '', $2; ## split the digits up into an array print "Input : $input\n\$site_code : \'$site_code\'\n\@rs :\n\t", (join "\n\t", @rs), "\n"; } else{ ## ... process alternately? print "input \'$input\' cannot be processed.\n"; } } __DATA__ uk1sxve01205.gfjgjf5.fdhd5 usasxve513.gfdhf4.hgfd4 how_did_this_get_here? #### Input : uk1sxve01205.gfjgjf5.fdhd5 $site_code : 'uk1' @rs : 0 1 2 0 5 Input : usasxve513.gfdhf4.hgfd4 $site_code : 'usa' @rs : 5 1 3 input 'how_did_this_get_here?' cannot be processed.