foreach $string ( "s005219/Doe John|John.Doe\\", "s0052194/Doe Thomas|Thomas.Doe\\", ) { if (m!/(.*?)\|!) { print("$1\n"); } }