To do something perfunctorily is to do it because you have to, as a formality, often in a careless way.
A perfunctory action is a formality: you do it because you have to, but you might not care if you do a good job. Similarly, to do something perfunctorily is to get it done without giving it much attention. A referee who does his job perfunctorily probably misses many calls. A teacher who teaches perfunctorily may grade student papers without reading them. A politician may shake hands perfunctorily, since he has to do it so often.