#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %hash; while (<>) { if (my ($key, $value) = /\.\\(.+?)-\d+;(.+?)\s-\s/) { $hash{$key} = $value; } else { warn "couldn't match key and value on line $."; } } print Dumper(\%hash);