sub a { my $p=shift; for($p){ while( s/_$//g || (m/_($word)\b/ && ( defined($dict{$1})) && s/_($word)\b/$dict{$1}_/g)|| (m/_($word)\b/ && ( defined($dict{lc($1)})) && s/_($word)\b/ ucfirst($dict{lc($1)})."_" /ge)|| (m/_($word)\b/ && ( !defined($tt{$1})) && s/_($word)\b/($1)_/g)|| s/_./ _/g || 0){}} $p ;} sub b { my $p=shift; for($p){ while( s/de o\b/do/g || 0){}} $p ;} %dict=(driver=>"motorista", the=>"o", of=>"de", car=>"carro"); $word='\w+'; if( b(a("_I see the Driver of the car")) eq "(I) (see) o Motorista do carro" ) {print "ok\n"} else {print "ko\n"}