#!/usr/bin/perl -w use strict; use Data::Dumper; my %mdata; # using for now open FI, "<", "f:\\cyclecount.txt" or die "open failed $!"; # get file from ini while () { chomp; next unless (s/\^/\^/g == 4); my @rec = split /\^/; # $mdata{PKEY} = $rec[0]; my $pkey = trim_trailing($rec[0]); %mdata = ( $pkey => { ABC => trim_trailing($rec[1]), DESC => trim_trailing($rec[2]), UNIT => trim_trailing($rec[3]), LOC => trim_trailing($rec[4]) } ) } close FI or warn $!; print Dumper \%mdata; sub trim_trailing { my $s = shift; $s =~ s/\s+$//; return $s } __DATA__ 0V704-B ^B^STERILE OR TOWELS ^CS/20 EA ^A/2/1 0ZS-050 ^B^ZERO WET SPLASHIELD ^EA ^H/2/1 00E7507 ^B^POLYHESIVE II ^CS/50 EA ^H/3/3 00ER320 ^A^APPLIER MULTIPLE CLIP MED/LG ^BX/3 EA ^G/6/4 00H-334 ^B^SUCTION POLY TRAP ^EA ^G/4/5 000V400 ^B^LAP SPONGES ^CS/40 EA ^A/2/1