import Text.Regex import Data.Maybe (fromJust) mail :: Regex mail = mkRegex "\\([a-zA-Z0-9]+\\)[[:blank:]]+\\([a-zA-Z0-9]+@[a-zA-Z0-9]+\\)" mainmatch s = case m of { Nothing -> [] ; Just (pre, mm, post, _) -> mm:mainmatch post } where m = Text.Regex.matchRegexAll mail s main = do s <- readFile "names" let sout = mainmatch s in print sout