ABD - some text ACDB- some more text WD - more text - which spills onto the next line SD - another line #### $myHash{'ABD'} = "some text" $myHash{'ACDB'} = "some more text" etc. #### /^([A-Z]{2,4})(\s{0,2})\-\s((.*)\n)*/g #### #!/usr/bin/perl use strict; use warnings; # The data my $data =<< "END"; ABD - some text ACDB- some more text WD - more text - which spills onto the next line SD - another line END # Search and replace a newline followed by four spaces # followed by a hyphen with nothing $data =~ s/\n(\s{4})-//ig; # Split the data into lines my @lines = split(/\n/, $data); # Scroll though the lines foreach my $line ( @lines ) { # start-foreach # Check to make sure our line is formatted correctly if ($line =~ /^(\S+)\s*-\s+(.+)$/) { # start-if # Get the values out of the regex my ( $key, $value ) = $line =~ /^(\S+)\s*-\s+(.+)$/; # Print the results print "$key, $value\n"; } # end-if # Else line is not formatted correctly else { # start-else print "Badly formatted line!\n"; } # end-else } # end-foreach