Abstract The dye 2-(5-amino-3,4-dicyano-2H-pyrrol-2-ylidene)-1,1,2-tricyanoethanide (L′, C11H2 N 7 − , λmax=549 nm), is a specific ligand for Hg2+ in water, undergoing a colour change from violet to blue on the formation of the corresponding monochelated pyrrolizanto [>HgL] complex (λmax=650 nm). The reactivity of L′ with several Hg(II)-salts (Hg(H2O)6·2ClO4, HgAc2, HgCl2, CH3HgAc) and with a number of salts of different metal cations (M+=Ag; M2+=Fe, Co, Ni, Cu, Zn, Cd, Sn, Pb, Pd, Pt; M3+=Ru, Rh, Ir, Au, La) has been studied in homogeneous solution and in a polymeric sol–gel thin film (thickness ∼600 A, CL′=0.3 M) of polyvinylformal/silica (PVF/SiO2), obtained by dip-coating the appropriate THF solution of AsPh4L′ on a glass support. In most cases a parallel reactivity has been observed: L′ is sensitive mostly to the perchlorate among the Hg(II)-salts and the interference from Mz+ consists mainly in a degradation of L′ with a consequent fading. The cross interferences of Hg2+ from Au3+ and Cu2+ have also been examined and have been found distinctly different in the two systems. The effect of the matrix material has been studied by ESCA analysis of L′-doped films after being soaked in the appropriate water solutions. PVF/SiO2, being a non-porous material, makes the response of L′-doped film to Hg2+ rather slow with associated a detection limit lower on the order of one magnitude than that of L′ in homogeneous solution (10 ppm for a response time of 10 min). The L′-doped film can be regenerated from the corresponding [>HgL]-doped film, exposing the latter to the vapour of a concentrated HCl aqueous solution.