#!/usr/bin/perl # http://perlmonks.org/?node_id=1191400 use strict; use warnings; my @array = qw( ULTRIX.CW18.72.0.3.IP-HOST1.log DEC_DECSTATION.CW180.72.0.3.IP_HOST_AL.log DEC_DECSTATION_ADDR.CW180.72.0.3.IP_HOST_al2.log FOR_VISITORS23_HOST.HL617.253.1101.2.IP_HOST_hostinfo.log FOR_VISITORS24_HOST.HL617.253.1101.2.IP_HOST_hostinfo2.log FOR_VISITORS25_HOST.HL617.253.1101.2.IP_HOST_webform3.log ); my %hash1; /^(.+?)\.(.+?)\.IP/ and push $hash1{$2}->@*, $1 for @array; use Data::Dumper; print Dumper \%hash1;