while(){ my ($item) = $1 if /user(?:\d+)\*(.*?)$/; next if $seen{$item}; print $item,"\n"; $seen{$item}++; }