use Data::Dumper; my %ids=map { chomp; #Get rid of the \n (split(/=/))[0,1] } grep( !(/^\s*#/||!/=/), ); print Data::Dumper->Dump([\%ids]); exit; __DATA__ #user=passwd test=prrft5142 tester=foo #This is a comment foo