$_ =~ /(\d*).*SWITCH\sFastEthernet(\d)/; # just an example on how to extract some data my $id = $1; # get the iD my $switchNr = $2; # get the number of the switch #### $CUST_NAME{$id} .= "\nSWITCH Fa$switchNr ..."; # append the output, already formatted