use strict; use warnings; use Data::Dumper; my @users; while () { m#^\s*(?[\w-]+) :x :(?\d+) :(?\d+) :(?[\w\s(),-]*) :(?[\w/]+) :(?[\w/]*)$#x or die "Malformed input [$_]"; push @users, { %+ }; } print Dumper \@users; __DATA__ root:x:0:0::/:/usr/bin/ksh paul:x:201:1::/home/paul:/usr/bin/ksh jdoe:x:202:1:John Doe:/home/jdoe:/usr/bin/ksh