my %image_hash = ( ); while () { # Limited scope of $search/$replace # You could just use split to split on whitespace: my ($search, $replace) = split; # Or if you want to split on the first single space character, and force only 2 items: # my ($search, $replace) = split ' ', $_, 2; # or you could use a regex: # my ($search, $replace) = m/([^ ]*) (.*)/); # Suppress uninitialized warnings. # check for non-zero length, # although eq '' checks should be fine, too. { no warnings 'uninitialized'; if ( length $search and length $replace ){ warn "Found uplicate entry for: $search\n" if exists $image_hash{$searc}; $image_hash{$search} = $replace; } } }