Given a string, find the first non-repeated character in it.E.g. yellow should return yThere are several solutions for this in other languages but I haven't seen one written in Perl.My main question is: can this be done in a more Perl-ish way or generally in an even shorter way?use strict;use warnings all;while (<DATA>){    while (m,(.),g)    {        my $c = $1;        if (s,$1,,g < 2)        {            print $c\n;            last;        }    }}__DATA__yellowtooth
Finding the first non-repeated character in a string
algorithm;regex;perl
Don't reinvent the wheel, there is a function (ie. singleton) in the package MoreUtils that does the job:#!/usr/bin/perluse Modern::Perl;use List::MoreUtils qw(singleton);while (<DATA>) {    chomp;    # don't forget it, it removes the linebreak.    # split explodes the string in character    # singleton keeps characters that appear only once    # ($first) contains the first character that appears only once.    my ($first) = singleton split//, $_;    say $first;}__DATA__yellowtoothOutput:yh